LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-11-2010, 05:32 AM   #1
puppymagic
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 66

Rep: Reputation: 4
Exclamation How does PHP/SQL database do it?


Let's say someone built an internal search engine for his website, and there is the text box where visitors can enter the words they want, and all goes well and it returns a set of results.

My question is, how does the PHP do it, without anyone logged in in the valid way? Don't we have to log in using a correct password first, if we want to take advantage of search engines running on PHP? Is it called the anonymous log-in? If yes, how do I do that? (as a php builder)

thanks, experts @LQ!
 
Old 03-11-2010, 05:36 AM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Well you don't need to log anyone in to call a function. All it needs to do is pass the search string to whatever search function you have. This function should ideally sanitise the search string, then use a mysql query.

I don't understand where the login element to your question is coming from, perhaps you could expand on this? Paste your code? etc.

Incidentally, this ought to be in the PHP programming subforum if a mod is about to do this?
 
1 members found this post helpful.
Old 03-11-2010, 05:37 AM   #3
puppymagic
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 66

Original Poster
Rep: Reputation: 4
Thanks for your quick answer~~ by the way, where is the best forum to receive help regarding php? Did you mean within LQ or some other place on the internet?
 
Old 03-11-2010, 05:39 AM   #4
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Rep: Reputation: 62
What I *think* the OP is saying is that usually you need a username/password to access the MySQL database. This is supplied by PHP to login to the MySQL database. Much as any other language would, such as Java or whatever.

If you mean something else, please clarify.
 
Old 03-11-2010, 05:43 AM   #5
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Yeah, there is one on here, a Mod should move this for you, so there is no real need to create a new post I don't think.

Consider the php (ish, untested, not-quite $1) code:
Code:
$string = $_POST['search_string']
$string = $this->sanitise_for_search( $string )
$query = mysql_query( "SELECT * FROM Table_of_contents VALUES WHERE Title=$string" )
Then whatever you're doing, be it using the mysql_get_object for row etc. (Or whatever the correct php method is)

On this, as you see, there is no need to test for logged in from $_COOKIE or so on

(My php is rusty)

Perhaps you could post the code you have for someone a little better at this than I to look at
 
Old 03-11-2010, 05:44 AM   #6
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Quote:
Originally Posted by arashi256 View Post
What I *think* the OP is saying is that usually you need a username/password to access the MySQL database. This is supplied by PHP to login to the MySQL database. Much as any other language would, such as Java or whatever.

If you mean something else, please clarify.
Ah, I hadn't considered that meaning
 
Old 03-11-2010, 06:13 AM   #7
puppymagic
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 66

Original Poster
Rep: Reputation: 4
Arashi, is it possible to access and search for information without a login/password? Isn't that what's happening, when we use the built-in search engines of the websites?

If that is possible and that is what's happening, how do php builders do that? Just like jamescondon stated?
 
Old 03-11-2010, 06:16 AM   #8
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Right, theres a lot of confusion here. What do you want, to be able to access a database without having the password to the database? Or do you want to know whether a user can search without having to login to the web-app it's self?

Basically, are you talking about accessing the database? Or doing it as search engines do; as in you don't need to have an account on google to use google
 
Old 03-11-2010, 06:33 AM   #9
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Rep: Reputation: 62
Quote:
Originally Posted by puppymagic View Post
Arashi, is it possible to access and search for information without a login/password? Isn't that what's happening, when we use the built-in search engines of the websites?

If that is possible and that is what's happening, how do php builders do that? Just like jamescondon stated?
I don't understand what you mean. A search engine is accessing a database, which presumably has a username and password attached to it. This username and password is supplied to the database by PHP - you don't enter anything manually.

Something like: -

Code:
<?php
    // Connect to database server
    $hd = mysql_connect("myhost", "username", "password") or die ("Unable to connect");
    // Select database
    mysql_select_db ("database", $hd) or die ("Unable to select database");
    // Execute sample query
    $res = mysql_query("SELECT * FROM customer", $hd) or die ("Unable to run query");
    // Query number of rows in rowset
    $nrows = mysql_num_rows($res);
    // Output
    echo "The query returned $nrows row(s):\n\n";
    // Iteration loop, for each row in rowset
    while ($row = mysql_fetch_assoc($res)) {
        // Assigning variables from cell values
        $data1 = $row["title"];
        $data2 = $row["fname"];
        $data3 = $row["lname"];
        $data4 = $row["phone"];
        // Outputting data to browser
        echo "ROW# $nr : $data1 $data2 $data3 $data4\n";
    }
    mysql_close($hd);
?>

Last edited by arashi256; 03-11-2010 at 06:36 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My SQL statement to delete an entry in MYSQL database fails in PHP ratchie Linux - Software 1 12-29-2008 02:48 AM
SQL Database Uses... Novatian Linux - Software 1 06-21-2008 01:18 PM
(my)sql: drop database doesn't remove database kpachopoulos Programming 3 09-19-2007 01:32 PM
TOMCAT and MS SQL database shane200_ Programming 0 05-31-2005 10:52 AM
php trying to connect to local sql, error no such database feetyouwell Programming 11 02-08-2005 12:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration