Jump to content

[Answered] Created New Mysql Database


Someday

Recommended Posts

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 2

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

 

I use the following code:

<?php

mysql_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. :)

Link to comment
Share on other sites

  1. mysql API has been deprecated. Please consider mysqli or PDO instead.
  2. 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());
    ?>


  • Like 1
Link to comment
Share on other sites

  1. mysql API has been deprecated. Please consider mysqli or PDO instead.
  2. 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.

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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.   Paste as plain text instead

  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...