Jump to content

Lost connection to MySQL server at 'reading initial communication packet'


Recommended Posts

I'm getting this error message:

 

"Lost connection to MySQL server at 'reading initial communication packet', system error: 111"

 

this is my php script:

 

<?php
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle & Ivan Guardado Castro
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

/************************
CONSTANTS
/************************/
define("*******", "YOUR HOST");
define("*********", "YOUR USER");
define("******", "YOUR USER PASSWORD");
define("**********", "YOUR DATABASE");

/************************
FUNCTIONS
/************************/
function connect($db, $user, $password){
$link = @mysql_connect($db, $user, $password);
if (!$link)
    die("Could not connect: ".mysql_error());
else{
	$db = mysql_select_db(DB);
	if(!$db)
		die("Could not select database: ".mysql_error());
	else return $link;
}
}
function getContent($link, $num){
$res = @mysql_query("SELECT date, user, message FROM shoutbox ORDER BY date DESC LIMIT ".$num, $link);
if(!$res)
	die("Error: ".mysql_error());
else
	return $res;
}
function insertMessage($user, $message){
$query = sprintf("INSERT INTO shoutbox(user, message) VALUES('%s', '%s');", mysql_real_escape_string(strip_tags($user)), mysql_real_escape_string(strip_tags($message)));
$res = @mysql_query($query);
if(!$res)
	die("Error: ".mysql_error());
else
	return $res;
}

/******************************
MANAGE REQUESTS
/******************************/
if(!$_POST['action']){
//We are redirecting people to our shoutbox page if they try to enter in our shoutbox.php
header ("Location: shoutbox.html"); 
}
else{
$link = connect(HOST, USER, PASSWORD);
switch($_POST['action']){
	case "update":
		$res = getContent($link, 20);
		while($row = mysql_fetch_array($res)){
			$result .= "<li><strong>".$row['user']."</strong><img src=\"css/images/bullet.gif\" alt=\"-\" />".
			$row['message']." <span class=\"date\">".
			$row['date']."</span></li>";
		}
		echo 
		$result;
		break;
	case "insert":
		echo insertMessage($_POST['nick'], $_POST['message']);
		break;
}
mysql_close($link);
}


?>

 

its a cut n paste from a tutorial on how to create a shout box, i have asked him for help on why it does not function correctly but he hasn't the time at present, just wondering if any of you would be able to help at all? thanks in advance.

On the account you are using on MySQL, check the permissions of what it can and can't access. It is probably just as simple as a permission error it sounds like to me. Either that, or you might need to contact your host for this one.

thanks for your suggestion, i did contact my host's tech support and this is what he found:

 

"Hello,

 

I have tested the database connection using a test script at http://www.360transport.co.uk/testdb.php and was able to connect to the database '360_transport_database' without any issue. So there is no server side issue which is preventing from database connection. I have checked the URL at http://www.360transport.co.uk/shoutbox.html and it seems that its trying to tech information from the script http://www.360transport.co.uk/shoutbox.php and the script at http://www.360transport.co.uk/shoutbox.php is showing some syntax error. You may need to correct the script and check it further.

 

 

If you have any further questions, please update the Support Console.

 

Sincerely,

 

Stan Valdez

Technical Specialist"

 

1) You need to turn on error reporting so you can see the errors that are occurring and fix them. Put this at the beginning of your php script

error_reporting(E_ALL);
ini_set("display_errors", 1);

Do NOT ignore any WARNINGS or NOTICES. They are the result of LOGIC errors and need to be fixed.

 

2) It looks like you may have incorrectly modified the connection data:

// FROM YOUR SCRIPT
define("*******", "YOUR HOST");
define("*********", "YOUR USER");
define("******", "YOUR USER PASSWORD");
define("**********", "YOUR DATABASE");

If you have *'d out the connection parameters, you may have done it backwards. Your connection information needs to be the SECOND parameter there NOT the first.

// SOMETHING LIKE THIS
define("HOST", "????"); // Replace the ??'s with your database server (probably localhost)
define("USER", "????"); // Replace the ??'s with your database user login name
define("PASSWORD", "????"); // Replace the ??'s with your database user's login password
define("DB", "????"); // Replace the ??'s with your database name

 

 

Thank you, i've swapped those over now to the second parimeter and added the error reporting on.

 

the findings are like this:

 

Notice: Use of undefined constant HOST - assumed 'HOST' in /hermes/bosweb/web132/b1325/ipg.360transportcouk/shoutbox.php on line 56

 

Notice: Use of undefined constant USER - assumed 'USER' in /hermes/bosweb/web132/b1325/ipg.360transportcouk/shoutbox.php on line 56

 

Notice: Use of undefined constant PASSWORD - assumed 'PASSWORD' in /hermes/bosweb/web132/b1325/**********/shoutbox.php on line 56

Could not connect: Lost connection to MySQL server at 'reading initial communication packet', system error: 111

 

 

Thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.