PHP/mySQL Puzzler  | | |
January 12th, 2002, 08:28 AM
|
#1 (permalink)
| | Junior Member
Join Date: Dec 2001 Location: Vero Beach, FL
Posts: 14
|
Scratching my head over this one.
I'm a veteran website designer, but a newbie to PHP and mySQL.
I've got Win32 versions of Apache, mySQL and PHP installed on a WinME box. Apache is functioning as localhost.
I can read the phpinfo.php page fine and it shows mySQL support is enabled, so I know Apache and PHP are talking to each other.
I've created a small database with one four-record table in mySQL for test purposes. In mySQLGUI, I can connect to it. I can also see the database and table using basic mySQL commands in DOS, i.e., mysqlshow.
The problem: the mysql_connect command in PHP refuses to work. The connect code comes straight out of the mySQL manual;
$link = mysql_connect("localhost", "root")
So why can't PHP connect to mySQL? It seems that somehow PHP can't find it. I'm certain mySQL is running when I try to connect to the database.
I know the database and table is there. I know Apache is working with PHP.
Any ideas on how to troubleshoot this? |
| |
January 12th, 2002, 08:41 AM
|
#2 (permalink)
| | Ultimate Member
Join Date: Jan 2002 Location: Brisbane, Aus.
Posts: 1,464
|
I am very new to PHP/MySQl and i was wondering if it might have something to do with needing a user to access that database?
__________________
--
www.theburningcat.com
All Your Cats Are Belong to Us
|
| |
January 12th, 2002, 08:45 AM
|
#3 (permalink)
| | Junior Member
Join Date: Dec 2001 Location: Vero Beach, FL
Posts: 14
|
The connect command specifies root as the user, that's all that's neccesary.
I neglected to note that I've got PHP running as a CGI process, not a server module within Apache, if that makes any difference. |
| |
January 12th, 2002, 08:51 AM
|
#4 (permalink)
| | Ultimate Member
Join Date: Jan 2002 Location: Brisbane, Aus.
Posts: 1,464
|
Um, try testing it. Make a mysql_query . See if you are connected or is it sending back an error?
Oh yeah Me Is a DOG! |
| |
January 12th, 2002, 09:05 AM
|
#5 (permalink)
| | Junior Member
Join Date: Dec 2001 Location: Vero Beach, FL
Posts: 14
|
I have tested it and it returns an error.
Here's the full text of page I'm trying to use with PHP. I'm reading it through Opera 6.0 with http://localhost/satcat2.php as the full URL.
It never gets past the mysql_connect line, returning an "Connected successfullyQuery failed" message in the browser.
<?php
// Connecting, selecting database
$link = mysql_connect("localhost", "root")
or die("Could not connect");
print "Connected successfully";
mysql_select_db("satcat")
or die("Could not select database");
// Performing SQL query
$query = "SELECT * FROM my_table";
$result = mysql_query($query)
or die("Query failed");
// Printing results in HTML
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
// Closing connection
mysql_close($link);
?> |
| |
January 12th, 2002, 09:11 AM
|
#6 (permalink)
| | Ultimate Member
Join Date: Jan 2002 Location: Brisbane, Aus.
Posts: 1,464
|
they had that same problem on the webserver. It just refused to talk to each other. I will talk to my admin tommorow when he brings around my new Delphi 6.0 disk  I will see if he can help you. |
| |
January 12th, 2002, 09:14 AM
|
#7 (permalink)
| | Ultimate Member
Join Date: Jan 2002 Location: Brisbane, Aus.
Posts: 1,464
|
Whoa, I just reread the error. and it says that you ahve connected successfull and that the prob was with Query. maybe you havn't got that data base right, still will talk to my admin. |
| |
January 12th, 2002, 09:18 AM
|
#8 (permalink)
| | Junior Member
Join Date: Dec 2001 Location: Vero Beach, FL
Posts: 14
|
You know, looking at that again, I have to wonder if the problem lies not in the mysql_connect query, but in the line:
print "Connected successfully";
The error message "Connected successfullyQuery failed" seems to suggest that this line is being passed to mySQL, which interprets it as a query and then rejects it.
Hmmm.
Think so? |
| |
January 12th, 2002, 09:43 AM
|
#9 (permalink)
| | Ultimate Member
Join Date: Jan 2002 Location: Brisbane, Aus.
Posts: 1,464
|
That does look a little suspisious. There seems to be no space there. yeah, maybe MySQl is interritating it. Try changing it and seeing if the error comes back with the new words.
As i said i am only new. i have read alot of info on it but not really put it to practise. So i am sorry if i aint much help. |
| |
January 12th, 2002, 10:11 AM
|
#10 (permalink)
| | Junior Member
Join Date: Dec 2001 Location: Vero Beach, FL
Posts: 14
|
Sure 'nuff - mySQL was choking on the print statement.
Once I removed that, and corrected the table name (it had been set to the default "my_table" in the script) it worked like a charm.
I don't understand yet what it was about the print statement that made it syntactically incorrect - maybe it needs to be sent as printf instead - but I'd like to know, if anyone understands what happened there.
Meantime, I can query the database now and pull stuff out of the table. Just being able to come online here and "think out loud" about the problem helped - it forced me to clarify the issue and look harder at exactly what was going on.
Next thing for me is creating a web-based form to make it easy to add stuff to the table. I might be back if I run into problems with that.
Charge!  |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |