0

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> 
5
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by cguan_77
1

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.. :))))

Edited by xjshiya: edited query

Votes + Comments
Thanks buddy :)
0

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.

Edited by pritaeas

0

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 :)

1

any ideas?

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

Votes + Comments
thanks :)
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.