home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

PHP/mySQL Puzzler

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2116
Discussions: 200,959, Posts: 2,379,531, Members: 246,329
Old January 12th, 2002, 08:28 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Dec 2001
Location: Vero Beach, FL
Posts: 14
PHP/mySQL Puzzler

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?
DeafScribe is offline   Reply With Quote
Old January 12th, 2002, 08:41 AM     #2 (permalink)
Ultimate Member
 
tobu's Avatar
 
Join Date: Jan 2002
Location: Brisbane, Aus.
Posts: 1,464
Send a message via ICQ to tobu Send a message via AIM to tobu Send a message via Yahoo to tobu
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
tobu is offline   Reply With Quote
Old 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.
DeafScribe is offline   Reply With Quote
Old January 12th, 2002, 08:51 AM     #4 (permalink)
Ultimate Member
 
tobu's Avatar
 
Join Date: Jan 2002
Location: Brisbane, Aus.
Posts: 1,464
Send a message via ICQ to tobu Send a message via AIM to tobu Send a message via Yahoo to tobu
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!
tobu is offline   Reply With Quote
Old 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);
?>
DeafScribe is offline   Reply With Quote
Old January 12th, 2002, 09:11 AM     #6 (permalink)
Ultimate Member
 
tobu's Avatar
 
Join Date: Jan 2002
Location: Brisbane, Aus.
Posts: 1,464
Send a message via ICQ to tobu Send a message via AIM to tobu Send a message via Yahoo to tobu
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.
tobu is offline   Reply With Quote
Old January 12th, 2002, 09:14 AM     #7 (permalink)
Ultimate Member
 
tobu's Avatar
 
Join Date: Jan 2002
Location: Brisbane, Aus.
Posts: 1,464
Send a message via ICQ to tobu Send a message via AIM to tobu Send a message via Yahoo to tobu
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.
tobu is offline   Reply With Quote
Old 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?
DeafScribe is offline   Reply With Quote
Old January 12th, 2002, 09:43 AM     #9 (permalink)
Ultimate Member
 
tobu's Avatar
 
Join Date: Jan 2002
Location: Brisbane, Aus.
Posts: 1,464
Send a message via ICQ to tobu Send a message via AIM to tobu Send a message via Yahoo to tobu
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.
tobu is offline   Reply With Quote
Old January 12th, 2002, 10:11 AM     #10 (permalink)
Junior Member
 
Join Date: Dec 2001
Location: Vero Beach, FL
Posts: 14
Got it whipped

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!
DeafScribe is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2969)
The disrespect of Obama by Russian .. (42)
Making Health Care Worse (179)
Wireless Televisions. (12)
CPU fan stops spinning randomly (9)
Regular Build (11)
windows 7 problem (7)
Laptop with wireless problem. (5)
windows vista security holes (13)
Print spooler problem (16)
Is the PSU I received dead? (12)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Recent Discussions
Print spooler problem (16)
Nvidia GTX 260 problem (0)
windows vista security holes (13)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
Open With ..... Win7 (1)
webcam (0)
upgrade for hp a6101 (0)
Laptop with wireless problem. (5)
Modern Warfare 2: Who Bought It? (64)
tv not turn on-makes clicking sound (2)
CPU fan stops spinning randomly (9)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
Point and Shoot Camera Suggestions. (4)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)


All times are GMT -4. The time now is 09:59 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28