hi guys, please help me out on this issue.

i had this code to connect to mysql using php but there is no any message displayed.

nothing is displayed on the screen, whether the connection is successful or there is an error.

any ideas?

i can connect to mysql using command prompt without a problem, but through this code below nothing is displayed on the screen.

any help is greatly appreciated.

<html>
<body>


<?php

$link = mysql_connect('localhost', 'my_username', 'my_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);

?>

</body>
</html> 

You didn't select the database you are going to use.. Do it like this..

<?php
$link=mysql_connect("localhost","my_username", "my_password");
if(!$link)
{
    die("Could not connect:" .mysql_error());
}

mysql_select_db("name_of_your_database"); //here goes the database selection
echo "Connected successfully!";
?>

Hope this helped.. :))))

commented: Thanks buddy :) +8

Selecting the database is optional, not required. Anyway, check your error log, to see if perhaps the mysql extension is not installed, or perhaps some other configuration errors. The code the OP provided is correct.

check sql extension care fully so it is good habit.

commented: thank you :) +8

hi guys, thanks for your replies.

there's nothing on the error log as well, I was hoping that there would be an error so there's something i could start with but i got no clue.

i'm just starting on this please bear with me, the extension we're talking about is it
the extension_dir on php.ini?

if that's the extension_dir on php.ini, i had set that one already.

i had checked the php info, i could see that mysql is loaded.

i'm really stucked, any ideas? thanks :)

any ideas?

Sorry. The code is fine, so it has to be a configuration thing, but that's difficult to guess.

commented: thanks :) +8

have u tried using double quotes instead of single quote.

hi guys, thanks for all your help.
i had installed WAMP and it works fine.
it's a bit troublesome installing the package one by one.

installing WAMP does everything. :) thanks again..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.