$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
mysql_close($dbh);
?>
The problem here is I am not getting any error message. The page does not display anything. But when i comment the mysql_coonect() line i can see the prints and echo's. I tried checking if $dbh is valid and also tried putting the code in an exception block. But nothing helps. I have tried many variations of the above code to no effect.
Please help me to identify the problem.
I am able to execute php scripts which shows that my php install is fine.
I am also able to login to mysql db using (locaalhost, root,pwd) in command prompt and using mysql workbench.
Php version = php-5.2.13-win32-
MySql version = mysql-essential-5.1.48-win32
Thanks
Richtofen
Last edited by Richtofen345; Jul 24th, 2010 at 10:45 am.
Re: Cannot connect to MySQL from PHP. No error message is displayed
Maybe the PHP configuration on the server running your script tells PHP not to display any errors (although I don't see any errors in your script.) Try adding the following line to the beginning of your script: ini_set('display_errors', 1); http://www.wallpaperama.com/forums/h...bled-t453.html
Re: Cannot connect to MySQL from PHP. No error message is displayed
After adding the lines mentioned by d5e5 & Chrishea i can see the error message. Thanks both of you.
I am getting this error message Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\loginValid.php on line 10
Looks like php cannot recognize my sql. My php install is php-5.2.13-win32-installer.msi.
After googling i found that i need to uncomment the following line from php.ini
;extension=php_mysql.dll
But i dont have the above line in my php.ini. It means something is missing even if i put the line i will not be able to get it to work.
I also do not have the extension_dir in my php home ( the line extension_dir is not there in php.ini)
Re: Cannot connect to MySQL from PHP. No error message is displayed
Your code looks fine.
It appears your php or mysql has not been installed correctly.
try using a differen connect function such as mysql_pconnect
and re-install your php or mysql.
f it is only that file just download that particular file and see if it works better.
perhaps try a different version of that file.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.