Jump to content

[Answered] Created New Mysql Database


Recommended Posts

Posted

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

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...