Closed Thread
Results 1 to 10 of 10

Thread: Can't connect to MySQL server by php code

  1. #1
    beamblues50 is offline x10Hosting Member beamblues50 is an unknown quantity at this point
    Join Date
    Sep 2011
    Posts
    7

    Can't connect to MySQL server by php code

    Hi. I have created a database and a user with their respective password. In my php code I have:

    $link = mysql_connect('localhost', 'my_user_name', 'my_password');
    if (!$link) {exit;}
    echo 'Connected successfully<br>';
    $db_selected = mysql_select_db('my_database_name', $link);
    if (!$db_selected) {
    die (mysql_error());}

    Then the result is:

    Connected successfully
    Access denied for user 'my_user_name'@'localhost' to database 'my_database_name'

    I'll tried add in cPanel Remote Database: 69.175.6.94, init.fris.x10hosting.com, and stoli.x10hosting.com, without improvement. The strangle is that by MyPHPadmin I can access and create/alter tables. Somebody can help me?

    Thanks,

  2. #2
    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,635

    Re: Can't connect to MySQL server by php code

    Exactly what is the db name? Are you sure it is correct? Did you add the DB user to the DB with all privileges?
    Nothing is always absolutely so.

  3. #3
    beamblues50 is offline x10Hosting Member beamblues50 is an unknown quantity at this point
    Join Date
    Sep 2011
    Posts
    7

    Re: Can't connect to MySQL server by php code

    My database is "marnel_sd". In the cPanel icon MySQL databases, I didn't discovered the options for the setting privileges; where are there?

  4. #4
    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,635

    Re: Can't connect to MySQL server by php code

    cPanel --> MySQL Databases
    When you add a DB user to a DB, a screen pops up and you must check ALL_PRIVILEGES
    Nothing is always absolutely so.

  5. #5
    beamblues50 is offline x10Hosting Member beamblues50 is an unknown quantity at this point
    Join Date
    Sep 2011
    Posts
    7

    Re: Can't connect to MySQL server by php code

    I have just created two new users. In no one I saw something with this for check this option..

  6. #6
    Dead-i's Avatar
    Dead-i is offline Community Advocate Dead-i has a spectacular aura about
    Join Date
    Aug 2011
    Location
    United Kingdom
    Posts
    1,445

    Re: Can't connect to MySQL server by php code

    So is your problem fixed?

    Also, this was documented in the Wiki, plus the MySQL Database Wizard guides you through the process step-by-step
    http://x10hosting.com/wiki/How_to_Cr...abase_and_User
    Last edited by Dead-i; 10-17-2011 at 11:04 AM.

  7. #7
    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,635

    Re: Can't connect to MySQL server by php code

    Quote Originally Posted by descalzo View Post
    cPanel --> MySQL Databases
    When you add a DB user to a DB, a screen pops up and you must check ALL_PRIVILEGES
    Not when you create it.
    Nothing is always absolutely so.

  8. #8
    beamblues50 is offline x10Hosting Member beamblues50 is an unknown quantity at this point
    Join Date
    Sep 2011
    Posts
    7

    Re: Can't connect to MySQL server by php code

    Very extrangle. I have created other new user, this time using the Internet Explorer and not the Firefox. And again also never appear the options for ALL PRIVILEGES. Am I making a mistake in something??

  9. #9
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    510

    Re: Can't connect to MySQL server by php code

    Hi beamblues50,

    If you are using MySQL® Databases (not the Wizard)



    At the bottom of the page, do you have the “Add User To Database”?


    You need to click on the Add button to set the privileges, as descalzo pointed out.

  10. #10
    beamblues50 is offline x10Hosting Member beamblues50 is an unknown quantity at this point
    Join Date
    Sep 2011
    Posts
    7

    Re: Can't connect to MySQL server by php code

    Quote Originally Posted by gomarc View Post
    Hi beamblues50,

    If you are using MySQL® Databases (not the Wizard)



    At the bottom of the page, do you have the “Add User To Database”?


    You need to click on the Add button to set the privileges, as descalzo pointed out.

    It's seems that already yet working!! Thanks you very much

    ---------- Post added at 05:34 PM ---------- Previous post was at 05:33 PM ----------

    It's seems that already yet working!! Thanks you very much.

Closed Thread

Similar Threads

  1. Replies: 2
    Last Post: 08-03-2011, 06:46 PM
  2. Replies: 1
    Last Post: 10-15-2010, 01:46 PM
  3. Replies: 2
    Last Post: 10-14-2010, 10:49 AM
  4. Replies: 2
    Last Post: 12-17-2007, 03:00 AM

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