Someday Posted February 5, 2014 Posted February 5, 2014 So im new to databases and php. Anyway, I created a new mySQL database, added a user and tried to connect thorugh php, but I get this message: Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 0 in/home/someday/public_html/mySQLDatabase.php on line 2Lost connection to MySQL server at 'reading initial communication packet', system error: 0 I use the following code:<?phpmysql_connect("johnny.heliohost.org:2082", "someday_someday", "CorrectPassword") or die(mysql_error());mysql_select_db("someday_Database") or die(mysql_error());?> I tried using somedayisle.heliohost.org as my local host; didnt work. The page loades for a long time, but only my first quote returns. Please help me.
lancersupraskyline Posted February 5, 2014 Posted February 5, 2014 mysql API has been deprecated. Please consider mysqli or PDO instead.The first parameter of mysql_connect is the MySQL server. Since PHP and MySQL resides on the same server, you should have used the string localhost instead. From tizag: When the PHP script and MySQL are on the same machine, you can use localhost as the address you wish to connect to. localhost is a shortcut to just have the machine connect to itself. If your MySQL service is running at a separate location you will need to insert the IP address or URL in place of localhost. Please contact your web host for more details if localhost does not work. In other words, <?php mysql_connect("localhost", "someday_someday", "CorrectPassword") or die(mysql_error()); mysql_select_db("someday_Database") or die(mysql_error()); ?> 1
Someday Posted February 6, 2014 Author Posted February 6, 2014 mysql API has been deprecated. Please consider mysqli or PDO instead. The first parameter of mysql_connect is the MySQL server. Since PHP and MySQL resides on the same server, you should have used the string localhost instead. From tizag: When the PHP script and MySQL are on the same machine, you can use localhost as the address you wish to connect to. localhost is a shortcut to just have the machine connect to itself. If your MySQL service is running at a separate location you will need to insert the IP address or URL in place of localhost. Please contact your web host for more details if localhost does not work. In other words, Thanks, it worked, but I never got it to work. So I cant use mysql on the server? I have to use mysqli? I'm sorry if this doesn't make sense; I don't know what I'm talking about. I'm following the tutorials at HTML.net on php.
Ice IT Support Posted February 6, 2014 Posted February 6, 2014 It's suggested that you use mysqli because the old mysql will no longer work in about a year or so. Basic mysqli is almost the same as mysql with a few minor changes. W3Schools has a good MySQLi tutorial for PHP: http://www.w3schools.com/php/php_mysql_intro.asp 1
Someday Posted February 6, 2014 Author Posted February 6, 2014 Just want to let people know it works now. Started mysqli instead. Many thanks, you can marked this as answered
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now