+ Reply to Thread
Results 1 to 7 of 7

Thread: pb with mysql_connect

  1. #1
    fomalhaut is offline x10Hosting Member fomalhaut is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    South of France near Arles
    Posts
    91

    Question pb with mysql_connect

    hello !

    I've some problem using the mysql_connect function :nuts:.
    This is the beginning of my script, that works fine on my own computer :

    <?php
    $con = mysql_connect("localhost:3306");
    $db = "usr_ayantdroit";
    if (!$con) {die('Connection impossible : ' . mysql_error());}
    mysql_select_db($db, $con);


    but it doesn't work on x10, bellow the error message :

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'usr'@'localhost' (using password: NO) in /home/usr/public_html/ident.php on line 4
    Connection impossible : Access denied for user 'usr'@'localhost' (using password: NO)


    line 4 is : $con = mysql_connect("localhost:3306"); (the second line above).

    I presume either localhost:3306 is to be replaced... by what ? ; or I must declare something in phpmyadmin or in mysql ? But I don't know what exactly.

    Does anyone can help me please ?

    Thanks.

  2. #2
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: pb with mysql_connect

    See http://be2.php.net/manual/en/function.mysql-connect.php :
    On your own machine you have a default user and no password, which works fine there. On x10hosting this is impossible and therefore you need to fill in the username and password to be able to connect to the mysql server.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: pb with mysql_connect

    mysql_connect("localhost", username, passwd );

    It is just "localhost", no port number.

    And you should consider using the mysqli_XXXX family of functions rather than the mysql_XXXX family. The 'i' is for 'improved'.
    Nothing is always absolutely so.

  4. #4
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: pb with mysql_connect

    To create a mysql user and database in cPanel, click on the mysql database wizard in the database section.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  5. #5
    fomalhaut is offline x10Hosting Member fomalhaut is an unknown quantity at this point
    Join Date
    Aug 2009
    Location
    South of France near Arles
    Posts
    91

    Re: pb with mysql_connect

    Thank you for your help.

    I've created a user with password for my database, and I've suppressed the port number.

    ... and it works fine.

    Thanks again. ;)

  6. #6
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: pb with mysql_connect

    Quote Originally Posted by descalzo View Post
    mysql_connect("localhost", username, passwd );

    It is just "localhost", no port number.

    And you should consider using the mysqli_XXXX family of functions rather than the mysql_XXXX family. The 'i' is for 'improved'.
    Definitely right on the improved vs regular mysql. However, the port is implicitly added whether you specify it explicitly or not, but you are better off not specifying it and letting PHP get it from the php config settings.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  7. #7
    archdesun's Avatar
    archdesun is offline x10Hosting Member archdesun is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    29

    Re: pb with mysql_connect

    Thank you for your help:nuts:
    :drool:Nothing is absolute, Nothing is forever, Nothing from nothing :drool:

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers