Skip navigation links

MySQL Forums :: PHP :: Cannot connect to MySQL using mysql_connect in PHP


Advanced Search

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

Hi,

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:

$hostname="localhost";
$mysql_login="admin";
$mysql_password="admin";
//$database="sampleapp";

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';
mysql_select_db($dbname);

echo $link;

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

Any help is appreciated.
Thanks,
Manysh

Options: ReplyQuote


Subject Written By Posted
Cannot connect to MySQL using mysql_connect in PHP Manysh S 03/08/2008 01:35PM
Re: Cannot connect to MySQL using mysql_connect in PHP Nick n 03/09/2008 02:29PM
Re: Cannot connect to MySQL using mysql_connect in PHP junn arsenal 05/01/2008 09:07PM
Re: Cannot connect to MySQL using mysql_connect in PHP Peter Brawley 05/01/2008 10:00PM
Re: Cannot connect to MySQL using mysql_connect in PHP per gunnar 05/06/2008 11:05AM
Re: Cannot connect to MySQL using mysql_connect in PHP Peter Brawley 05/07/2008 10:03AM
Re: Cannot connect to MySQL using mysql_connect in PHP Muiz Adeniran 05/09/2008 09:56AM
Re: Cannot connect to MySQL using mysql_connect in PHP per gunnar 05/13/2008 02:07PM
Re: Cannot connect to MySQL using mysql_connect in PHP Peter Brawley 05/13/2008 03:08PM
Re: Cannot connect to MySQL using mysql_connect in PHP per gunnar 05/14/2008 01:04PM
Re: Cannot connect to MySQL using mysql_connect in PHP Peter Brawley 05/14/2008 09:29PM
Re: Cannot connect to MySQL using mysql_connect in PHP per gunnar 05/16/2008 10:30AM


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.