943,935 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 6804
  • PHP RSS
Jul 25th, 2007
0

cannot connect to mysql server

Expand Post »
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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muruganasm is offline Offline
3 posts
since Jul 2007
Jul 25th, 2007
0

Re: cannot connect to mysql server

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.
Reputation Points: 35
Solved Threads: 5
Junior Poster
dr4g is offline Offline
136 posts
since Apr 2007
Dec 30th, 2008
0

Re: cannot connect to mysql server

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 Syntax (Toggle Plain Text)
  1. <?php
  2. // Connect to the database
  3. $dbhost = 'localhost';
  4. $dbusername = 'testuser';
  5. $dbpasswd = 'testpassword';
  6. $database_name = 'simple';
  7. $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
  8. or die ('Couldn\'t connect to server.');
  9. $db = mysql_select_db("$database_name", $connection)
  10. or die('Couldn\'t select database.');
  11.  
  12. // Generate SQL code to store data on database.
  13. $insert_sql = 'INSERT INTO simple_table (text) VALUES (\'test text, 1,2,3\')';
  14.  
  15. // Execute SQL code.
  16. mysql_query( $insert_sql )
  17. or die ( 'It Didn€™t Work: ' . mysql_error() );
  18.  
  19. // Tell User we are done.
  20. echo 'Code Inserted';
  21. ?>
  22.  
  23. Create a new file called "test_select_mysql.php" and enter the following code into it:
  24.  
  25. <?php
  26. // Connect to the database
  27. $dbhost = 'localhost';
  28. $dbusername = 'testuser';
  29. $dbpasswd = 'testpassword';
  30. $database_name = 'simple';
  31. $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
  32. or die ('Couldn\'t connect to server.');
  33. $db = mysql_select_db("$database_name", $connection)
  34. or die('Couldn\'t select database.');
  35.  
  36. // Generate code to retrieve data from database.
  37. $select_sql = 'SELECT text FROM simple_table';
  38.  
  39. // Retrieve code from database.
  40. $result = mysql_query( $select_sql )
  41. or die ( 'It Didn€™t Work: ' . mysql_error() );
  42.  
  43. // Display results to user.
  44. while ( $row = mysql_fetch_object ( $result ) )
  45. {
  46. echo $row->text . ‘<br>’;
  47. }
  48. ?>

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.
Last edited by peter_budo; Jan 6th, 2009 at 1:59 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mayacn is offline Offline
1 posts
since Dec 2008
Jan 2nd, 2009
1

Re: cannot connect to mysql server

hi!
Just write according to my code.I think that will work.
php Syntax (Toggle Plain Text)
  1. <?php
  2. $host="localhost";
  3. $user="root" //It may different
  4. $pass="" //If u use password that write between " "
  5. $database="test" //you can also use any any created database name.
  6. @mysql_connect($host,$user,$pass) or die("Sorry ,User name Or Password problem);
  7. @mysql_select_db($database);
  8.  
  9. //What's you want to do write in here.
  10.  
  11. //More comple Email me: <EMAIL SNIPPED>
  12.  
  13. ?>
  14.  
Last edited by peter_budo; Jan 6th, 2009 at 2:00 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sumchtarek is offline Offline
4 posts
since Jan 2009
Jan 3rd, 2009
0

Re: cannot connect to mysql server

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.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005
Feb 7th, 2010
0

thnx...

Click to Expand / Collapse  Quote originally posted by sumchtarek ...
hi!
Just write according to my code.I think that will work.
php Syntax (Toggle Plain Text)
  1. <?php
  2. $host="localhost";
  3. $user="root" //It may different
  4. $pass="" //If u use password that write between " "
  5. $database="test" //you can also use any any created database name.
  6. @mysql_connect($host,$user,$pass) or die("Sorry ,User name Or Password problem);
  7. @mysql_select_db($database);
  8.  
  9. //What's you want to do write in here.
  10.  
  11. //More comple Email me: <EMAIL SNIPPED>
  12.  
  13. ?>
  14.  
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alza is offline Offline
1 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Update password using php.
Next Thread in PHP Forum Timeline: Very simple PHP include problem!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC