Jump to content


Photo

Newbie question: error conecting to MySQL server


  • Please log in to reply
8 replies to this topic

#1 MordoSairon

MordoSairon

    Newbie

  • Member
  • Pip
  • 6 posts
  • Location:Madrid (SPAIN)
  • Main OS: Windows XP

Posted 18 April 2010 - 08:42 AM

Hello!

I'm following Quick MySQL guide and I can't complete point 2: PHP Connect. I get this warning message:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in W:\www\open_db.php on line 2
Error connecting to mysql


I've checked password is ok and apparently server is running (if I change dbhost for a non existent, I get a different error). My last idea is that maybe there's a port problem, because I change server listener port from 80 to 8080 due to initial problems with php. This is rather an intuition than a good idea xD but I don't know anything else to try. Also if the listener port is the problem, I don't know how to fix it ^^U

Thank you in advance for your help.

Best regards! ^^


[EDIT]

I tried to include my particular listener port like this:

$dbhost = 'localhost:8080'; //server name localhost or 127.0.0.1

Now I get this message:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in W:\www\open_db.php on line 2

Fatal error: Maximum execution time of 30 seconds exceeded in W:\www\open_db.php on line 2


Now I really don't know what else can I do :S

[/EDIT]
/** @author William Shakespeare */
#define question(to) ? (B) : ~(B)

#2 Znote

Znote

    Junior Member

  • Member
  • Pip
  • 37 posts
  • Gender:Male
  • Main OS: Windows 7

Posted 02 May 2010 - 05:51 AM

I believe I have the same error. S:

I am representing the open tibia community otland.net
otland.net is contributing open source server software to an 2d mmorpg game called Tibia.

Here are some Uniform server tutorials/guide contributions from me:
VIDEO TUTORIAL: I teach newbreeds to install and operate uniform server: (Updated for Coral 8.x)
http://youtu.be/AsyxPhDTOcI

Uniform Server newbie guide:
Securely installing Uniform Server for total newbeginners:
http://otland.net/f4...-0-3-6-a-77593/
(also contains how to get our open source tibia game, and connect it successfully to the uniform mysql server).

How to add a website for our open source tibia game which includes highscore, create account and so on: (On uniform server)
http://otland.net/f4...m-server-91951/


#3 kalpz

kalpz

    Beta Team Member

  • Beta Tester
  • PipPip
  • 132 posts
  • Location:New Zealand
  • IRC Nickname: LifeSteala
  • Main OS: Windows Vista

Posted 05 May 2010 - 07:42 PM

Hi there,
You only need to connect to localhost without any port. MySQL runs on port 3306 by default.

Please try:

$dbhost = "localhost";

If you are still having a problem.. find this code:

mysql_connect($dbhost, $dbuser, $dbpass);

and ensure it looks like this:

mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());

This will show a better error - you may show us this so we can further determine what is happening.
ATOMIC Web Hosting 2007 - 2011
Shared Hosting - Reseller Hosting - Dedicated Servers - Virtual Private Servers (Request Dedicated/VPS Servers via E-mail)
E-mail: sales@atomicwebhosting.com Website: http://www.atomicwebhosting.com/

#4 MordoSairon

MordoSairon

    Newbie

  • Member
  • Pip
  • 6 posts
  • Location:Madrid (SPAIN)
  • Main OS: Windows XP

Posted 08 May 2010 - 05:01 AM

Hello!

I've change my code to see full description error and erased port 8080 from dbhost, but I don't see anything new:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in W:\www\open_db.php on line 2
Can't connect to MySQL server on 'localhost' (10061)


Maybe it's a port problem? Should I change for another one or enable it someway?

Thank you very much!

Best regards,


[EDIT] I changed port to 3307, but I didn't get any results. I don't know if netstat command should show any status line for mysql listening port, but it doesn't show anything (even for 3306 before changing port). [/EDIT]
/** @author William Shakespeare */
#define question(to) ? (B) : ~(B)

#5 Voda

Voda

    Newbie

  • Member
  • Pip
  • 2 posts
  • Main OS: Windows XP

Posted 29 May 2010 - 03:02 AM

According to php tutorial, once you have created a database, there are a few ways you can connect to it.
To connect from a PHP script, just put this in your file:
<?
	 mysql_connect("DBSERVER", "DBUSERNAME", "DBPASSWORD");
	 mysql_select_db("DBNAME");
	 ?>
using the following substitutions for the bold terms as above, plus substituting DBPASSWORD with your own mysql password:

* Replace DBSERVER with the correct database servername for your site.
* Replace DBUSERNAME with your own mysql username.
* Replace DBNAME with your own mysql databasename.

The connection will be closed automatically when the script ends. To close the connection before, use the mysql_close() function:
<?php
 $con = mysql_connect("localhost","peter","abc123");
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }
 // some code
 mysql_close($con);
 ?>


#6 BobS

BobS

    Project Helper

  • Super Moderator
  • PipPipPip
  • 334 posts
  • Location:Santiago Chile
  • Interests:Retiring, computer systems, system design, model railroads....
  • Wiki ID: BobS
  • Main OS: Windows 7

Posted 24 June 2010 - 02:42 PM

Hello!

I've change my code to see full description error and erased port 8080 from dbhost, but I don't see anything new:
Maybe it's a port problem? Should I change for another one or enable it someway?

Thank you very much!

Best regards,
[EDIT] I changed port to 3307, but I didn't get any results. I don't know if netstat command should show any status line for mysql listening port, but it doesn't show anything (even for 3306 before changing port). [/EDIT]


Instead of using "localhost", put in "127.0.0.1" for the dbhost.

See refs to Windows 7 and MySQL.

#7 MordoSairon

MordoSairon

    Newbie

  • Member
  • Pip
  • 6 posts
  • Location:Madrid (SPAIN)
  • Main OS: Windows XP

Posted 01 July 2010 - 11:39 AM

Voda: thanks for your help, I'm following tutorial as well and I think mi code is correct:

This is my config_db.php:
<? // Database configuration file config_db.php
$dbhost = 'localhost'; //server name localhost or 127.0.0.1
$dbuser = 'root';	  //User name default root 
$dbpass = 'root';  //Password default root -- I will be using ''fred123''
?>

And this is open_db.php:
<? // Open database open_db.php
include_once $_SERVER['DOCUMENT_ROOT'] . "/config_db.php";

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
?>

I get this error when executing open_db.php. I think everything is correct, it's the same code in the tutorial (except the include_once, but that's not failing :S).

BobS: I've already tried that, I see no difference but that in the error message shows '127.0.0.1' instead of 'localhost' :S

See refs to Windows 7 and MySQL.

I'm running on Windows XP, I've already search this error in google but dind't find a solution.

Thank you very much for your help.

Best regards,
/** @author William Shakespeare */
#define question(to) ? (B) : ~(B)

#8 Ric

Ric

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 1,535 posts
  • Gender:Male
  • Location:Cambridge,UK
  • Interests:Electronics
    Internet in general
    Open source projects
  • SourceForge IDmpgcan
  • Wiki ID: Ric
  • Main OS: Windows XP

Posted 01 July 2010 - 02:32 PM

I canít see anything wrong with your code.
I assume the error message is similar to this:
Can't connect to MySQL server on 'localhost' (10061)
One cause of the above error your firewall may be blocking connection on port 3306.

Disconnect your PC from the Internets and disable your firewall.
Restart servers and see if you can connect to MySQL server.
If that works you need to add an exception in your firewall to allow MySQL connection.

Before connecting to Internet remember to restart your firewall

General notes:
I assume you are using an older version of Uniform Server because PHP short tags (<? ?>) are working.
Your code will not run on newer version that run PHP 5.3.* always use full tags
(<?php ?>)

On Windows XP you can use either "127.0.0.1" or locahost for dbhost

All the best
Ric :)

#9 MordoSairon

MordoSairon

    Newbie

  • Member
  • Pip
  • 6 posts
  • Location:Madrid (SPAIN)
  • Main OS: Windows XP

Posted 04 July 2010 - 05:22 AM

Hello!

Thank you very much for your help. My message error is exactly:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in W:\www\open_db.php on line 4
Can't connect to MySQL server on 'localhost' (10061)


I've tried to disconnect from the internet and then shut down my firewall. After stop and restart server I see no difference (same error message). Anyway, I've already thought about the firewall an added an exception for mysql like this:

Posted Image


I think like this there shouldn't be any problems of communication but who really knows...

Best regards,
/** @author William Shakespeare */
#define question(to) ? (B) : ~(B)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users