PDA

View Full Version : Call to undefined function mysql_connect()


jamesparkhyde
10-30-2009, 06:21 AM
I am setting up my development environment. Windows XP 32 bit, Apache 2.2, PHP 5.3, MySQL 5.1. It all looks good until I try this test script:

<?php
// hostname or ip of server (for local testing, localhost should work)
$dbServer='localhost';

// username and password to log onto db server
$dbUser='root';
$dbPass='';
// name of database
$dbName='test';

$link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");
print "Connected successfully<br>";
mysql_select_db("$dbName") or die("Could not select database");
print "Database selected successfully<br>";

// close connection
mysql_close($link);
?>

... and I get the mysql_connect error.

There's a lot of documentation around this, but nothing so far has led me to success... the next thing I'm going to try is to remove everything php-ish and re-install it (per one of the suggetions I read). Any other ideas?

Thanks!

Jim.





$dbPass='(mypassword)';

DWcourse
10-30-2009, 10:41 PM
James is a student of mine, and not being all that proficient with Apache on Windows I wasn't able to help him figure this one out. Any help would be appreciated.

I believe the error was: "Fatal error: Call to undefined function mysql_connect() in C:\public_html\mysqltest.php on line 12"

jamesparkhyde
10-31-2009, 01:08 AM
After trying about 20 suggestions gleaned from a web search on the error message, I have added files, moved files and modified files in php and apache, and my system path and environment variables, all without solving the problem. In fact it just got worse and I was no longer able to run php scripts in my browser, not to mention still unable to connect to MySQL. So (once again) I ripped out everything apache, MySQL and php-ish and started over. I installed the wamp from wampserver.com and LO! it all works! No idea what changed, but Oh well...

edbr
10-31-2009, 01:43 AM
glad its sorted but i would have said
$link = mysql_connect("$dbServer", "$dbUser", "$dbPass") should be
$link = mysql_connect($dbServer, $dbUser, $dbPass)

DWcourse
10-31-2009, 01:47 AM
glad its sorted but i would have said
$link = mysql_connect("$dbServer", "$dbUser", "$dbPass") should be
$link = mysql_connect($dbServer, $dbUser, $dbPass)

I'd bet you're right!

jamesparkhyde
10-31-2009, 05:47 AM
Well, you may very well be right about the quotes under the way I had it set up before, but now I'm running the very same code - with the quotes - and it's working.

I tried it without the quotes and it works that way too. Is that strange, or normal?