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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
konstandinos
Forum Commoner
Posts: 68
Joined: Wed Oct 04, 2006 4:20 am

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

Post 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.
ody
Forum Contributor
Posts: 147
Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
konstandinos
Forum Commoner
Posts: 68
Joined: Wed Oct 04, 2006 4:20 am

Post 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?
konstandinos
Forum Commoner
Posts: 68
Joined: Wed Oct 04, 2006 4:20 am

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Post Reply