MySQL Forums
Forum List  »  PHP

Cannot connect to MySQL using mysql_connect in PHP
Posted by: Manysh S
Date: March 08, 2008 01:35PM


I am trying to make a connection to the MySQL database from PHP but it seems like I am missing a step or something and hence cannot connect to the database. I have tried everything but I can't figure out why. Please suggest/help (I am a beginner in PHP/MySQL/Apache).

I am using MySQL 5.0.51a-community-nt on my Windows XP machine. PHP version used is 5.2 and Apache version is 2.2.

Code Snippet:


echo "Print this..."; // THIS MESSAGE IS PRINTED

$link = mysql_connect($hostname,$mysql_login,$mysql_password);

echo " After connecting to the database..."; // THIS DOES NOT PRINT
if (!$link) {
die (mysql_error()); // NOR THIS ONE

$dbname = 'sampleapp';

echo $link;

if (!$link) {
die('Could not connect: ' . mysql_error());
echo "Some problem here....";
//echo 'Connected successfully';

Any help is appreciated.

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.