hi.
i am senthilmurugan. i am learning to php language.
one error occur. i try to connect to database.
Can't connect to MySQL server on 'localhost' (10061). how to correct the error .
please reply the answer...

Your Database information is incorrect
In order to connect you will need to have the valid information for;

DB Name
DB Username
DB Userpass
DB Host

One of these is incorrect.

hallo ppl,

i also have the same problem,

my php connection with MySQL is not working, and couldnt connect to server is displayed y my PHP

should i alter PHP's php.ini to access mysql?

is there any restriction that i have to store the Mysql directly in my C drive... if so i have currently installed in C:\Program Files\MySQL\MySQL Server 4.1

how can i change?

thanks in advance


this is what i did

<?php
 // Connect to the database
 $dbhost = 'localhost';
 $dbusername = 'testuser';
 $dbpasswd = 'testpassword';
 $database_name = 'simple';
 $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
  or die ('Couldn\'t connect to server.');
 $db = mysql_select_db("$database_name", $connection)
  or die('Couldn\'t select database.');

 // Generate SQL code to store data on database.
 $insert_sql = 'INSERT INTO simple_table (text) VALUES (\'test text, 1,2,3\')';

 // Execute SQL code.
 mysql_query( $insert_sql )
  or die ( 'It Didn\’t Work: ' . mysql_error() );

 // Tell User we are done.
 echo 'Code Inserted';
?>

Create a new file called "test_select_mysql.php" and enter the following code into it:

<?php
 // Connect to the database
 $dbhost = 'localhost';
 $dbusername = 'testuser';
 $dbpasswd = 'testpassword';
 $database_name = 'simple';
 $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
  or die ('Couldn\'t connect to server.');
 $db = mysql_select_db("$database_name", $connection)
  or die('Couldn\'t select database.');

 // Generate code to retrieve data from database.
 $select_sql = 'SELECT text FROM simple_table';

 // Retrieve code from database.
 $result = mysql_query( $select_sql )
  or die ( 'It Didn\’t Work: ' . mysql_error() );

 // Display results to user.
 while ( $row = mysql_fetch_object ( $result ) )
 {
  echo $row->text . ‘<br>’;
 }
?>

Browse to http://localhost/test_insert_sql.php, then http://localhost/test_select_sql.php. Every time you view test_insert_sql.php, it adds a line to the database; viewable from test_select_sql.php. Now, even if you reset you computer the data is still stored in the database.

hi!
Just write according to my code.I think that will work.

<?php
$host="localhost";
$user="root"  //It may different
$pass=""    //If u use password that write between " "
$database="test"  //you can also use any any created database name.
@mysql_connect($host,$user,$pass) or die("Sorry ,User name Or Password problem);
@mysql_select_db($database);

//What's you want to do write in here.

//More comple Email me:   <EMAIL SNIPPED>

?>

You might want to check with your hosting company about the MySQL connection. Not all hosting companies allow you to connect via localhost.

With GoDaddy and some others the MySQL database resides on a different server so they use a different sever name.

hi!
Just write according to my code.I think that will work.

<?php
$host="localhost";
$user="root"  //It may different
$pass=""    //If u use password that write between " "
$database="test"  //you can also use any any created database name.
@mysql_connect($host,$user,$pass) or die("Sorry ,User name Or Password problem);
@mysql_select_db($database);

//What's you want to do write in here.

//More comple Email me:   <EMAIL SNIPPED>

?>

Thnx 4 sharin' the code ...I was havin' really havin' hard time connecting to mySql .... by the help of ur code.. my problem has been sorted out.

This article has been dead for over six months. Start a new discussion instead.