Page 1 of 1

can't connect to mysql database and die message not showing.

Posted: Wed Oct 04, 2006 4:25 am
by konstandinos
hello all.

i'm a newbie to php, but a relatively experienced coder, so feel free to be technical.

i've installed apache, php and mysql.

my php script (embedded in html) is as follows:

Code: Select all

<?php
	echo "before";
	
        $connection = mysql_connect("localhost", "root", "mypassword") or die("Failed to connect to database: " . mysql_error());
	
	echo "Connected to database.";
?>
now the strange thing is that in my html output, i get "before" printed out, but then nothing. there is more html code below the php block that doesn't get print out either (tables and lines etc). so its literally halting at the mysql_connect line.

but nothing gets printed out from the die message, so i have no clue how to troubleshoot it.

phpinfo(); returns the php settings so i know ive configured php fine.

also i followed a mysql installation tutorial step by step and have created tables and populated them, so thats working fine.

any ideas?

thanks.

Posted: Wed Oct 04, 2006 5:05 am
by ody
Chances are mysql is not configured with php correctly and it is just not displaying that error as error reporting is most likely turned off in your php.ini

Posted: Wed Oct 04, 2006 6:19 am
by volka
Maybe php timed out.
The webserver probably has an error log (error.log for apache). Is something in there related to the problem?

Posted: Wed Oct 04, 2006 8:36 am
by konstandinos
ok in apache's error log i found this:

[error] [client 127.0.0.1] PHP Fatal error: Call to undefined function mysql_connect()

so i assume that php hasn't been configured properly. but i followed the installation instructions.

what did i miss out?

Posted: Wed Oct 04, 2006 8:53 am
by konstandinos
aha!

managed to sort out problem

a little research revealed that php5 doesn't enable mysql by default.

i had to copy the libmysql.dll file from my php folder into my windows folder (or i could have added php to my PATH environment setting).

works like a breeze now.

thanks for the help guys

Posted: Wed Oct 04, 2006 9:08 am
by volka
keep an eye on the error.log
It seems your php installation does not send error messages to the client, but you can see them in that file.

There are mainly three paraemters in your php.ini that control the error reporting behaviour of php
error_reporting, display_errors and display_startup_errors
error_reporting should be E_ALL on your development server.
<?php phpinfo(); ?> tells you which php.ini you have to edit. You probably have to restart your webserver (software) after changing parameters there.