andy_b_1502 Posted February 5, 2012 Share Posted February 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256452-lost-connection-to-mysql-server-at-reading-initial-communication-packet/ Share on other sites More sharing options...
andy_b_1502 Posted February 5, 2012 Author Share Posted February 5, 2012 http://www.360transport.co.uk/shoutbox.html Quote Link to comment https://forums.phpfreaks.com/topic/256452-lost-connection-to-mysql-server-at-reading-initial-communication-packet/#findComment-1314721 Share on other sites More sharing options...
cooldood Posted February 6, 2012 Share Posted February 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256452-lost-connection-to-mysql-server-at-reading-initial-communication-packet/#findComment-1314966 Share on other sites More sharing options...
andy_b_1502 Posted February 6, 2012 Author Share Posted February 6, 2012 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" Quote Link to comment https://forums.phpfreaks.com/topic/256452-lost-connection-to-mysql-server-at-reading-initial-communication-packet/#findComment-1315197 Share on other sites More sharing options...
DavidAM Posted February 6, 2012 Share Posted February 6, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256452-lost-connection-to-mysql-server-at-reading-initial-communication-packet/#findComment-1315249 Share on other sites More sharing options...
andy_b_1502 Posted February 9, 2012 Author Share Posted February 9, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256452-lost-connection-to-mysql-server-at-reading-initial-communication-packet/#findComment-1316196 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.