+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: How to connect my php script to database?

  1. #1
    flash.engine50 is offline x10Hosting Member flash.engine50 is an unknown quantity at this point
    Join Date
    Jan 2011
    Posts
    7

    How to connect my php script to database?

    Hi, I am here new and I don't know what I have to do. I have read somethings in forum, but I didn't find.
    I have created database, mysql user, added user to database and I gave all permission to user.

    my php script:

    $host="localhost"; // Host name
    $username="hawksvk_fe"; // Mysql username
    $password="mypassword"; // Mysql password
    $db_name="hawksvk_database"; // Database name

    //Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
    mysql_select_db("$db_name")or die("cannot select DB");

    Result: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'hawksvk_fe'@'web7.vital.x10hosting.com' (using password: YES) in /home/hawksvk/public_html/aaa.php on line 11

    Please help me, thank you.

  2. #2
    niagaradad is offline x10Hosting Member niagaradad is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    9

    Re: How to connect my php script to database?

    you are passing in a password, are you sure it is the correct password? If the password wasn't being accepted it would say (using password: No).
    Last edited by niagaradad; 01-28-2011 at 03:01 PM.

  3. #3
    MaestroFX1's Avatar
    MaestroFX1 is offline Community Advocate MaestroFX1 has a spectacular aura about
    Join Date
    Feb 2008
    Location
    Area 51
    Posts
    1,577

    Re: How to connect my php script to database?

    Post the full script or at least post what's around line 11.

    Because the lines that you have posted alone can't do that.

    There would be only two outcomes in this case(error)
    #1 cannot connect to server
    #2 cannot select DB

  4. #4
    flash.engine50 is offline x10Hosting Member flash.engine50 is an unknown quantity at this point
    Join Date
    Jan 2011
    Posts
    7

    Re: How to connect my php script to database?

    mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); //this is line 11, password is good

  5. #5
    MaestroFX1's Avatar
    MaestroFX1 is offline Community Advocate MaestroFX1 has a spectacular aura about
    Join Date
    Feb 2008
    Location
    Area 51
    Posts
    1,577

    Re: How to connect my php script to database?

    What is the url for the faulty page ?

  6. #6
    flash.engine50 is offline x10Hosting Member flash.engine50 is an unknown quantity at this point
    Join Date
    Jan 2011
    Posts
    7

    Re: How to connect my php script to database?

    http://flash-engine.pcriot.com/aaa.php

    Can I use Mysql database, if I have only freehosting here?
    Last edited by flash.engine50; 01-29-2011 at 03:57 AM.

  7. #7
    MaestroFX1's Avatar
    MaestroFX1 is offline Community Advocate MaestroFX1 has a spectacular aura about
    Join Date
    Feb 2008
    Location
    Area 51
    Posts
    1,577

    Re: How to connect my php script to database?

    Quote Originally Posted by flash.engine50 View Post

    Can I use Mysql database, if I have only freehosting here?
    You are allowed to use upto 2 Databases.
    MySQL and PostGRE both are supported.

    Check out your cPanel page.

  8. #8
    flash.engine50 is offline x10Hosting Member flash.engine50 is an unknown quantity at this point
    Join Date
    Jan 2011
    Posts
    7

    Re: How to connect my php script to database?

    Is something more, what I have to set?

  9. #9
    MaestroFX1's Avatar
    MaestroFX1 is offline Community Advocate MaestroFX1 has a spectacular aura about
    Join Date
    Feb 2008
    Location
    Area 51
    Posts
    1,577

    Re: How to connect my php script to database?

    Just now I (re)generated the error on my and clearly arrived at conclusion that it is an “authentication error”.

    Follow this step-by-step:

    1. Go to your cPanel page and click “MySQL Database Wizard”, you will be asked to create a database (mysql).
    Type a name for your database,for example – mydb001.

    $db_name = yourusername_whatyoutypedjustnow.

    For you, $dbname = hawksvk_mydb001 //to be used in php

    Click Next.

    2. Enter username and password “for the database” (hawksvk_mydb001).
    Characters for username <= 7.
    $username = hawksvk_usr001 //to be used in php

    3. Temporarily grant all privileges and proceed.

    4. You will get conformation that
    User hawksvk_usr001 was added to the database hawksvk_mydb001.

    Check this page “MySQL Databases” before you go any further to ascertain that the created database and user are linked with each other.
    If not, use “Add User To Database“and link them.

    Now, php section:

    ------start of code

    <?
    $host="localhost"; // Host name
    $username=" hawksvk_usr001"; // Mysql username
    $password="mypassword"; // Mysql password
    $db_name=" hawksvk_mydb001"; // Database name

    //Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
    mysql_select_db("$db_name")or die("cannot select DB");

    ?>
    ------end of code

  10. #10
    flash.engine50 is offline x10Hosting Member flash.engine50 is an unknown quantity at this point
    Join Date
    Jan 2011
    Posts
    7

    Re: How to connect my php script to database?

    I have made all. Now it is this same.

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user ' hawksvk_usr001'@'web7.vital.x10hosting.com' (using password: YES) in /home/hawksvk/public_html/aaa.php on line 8

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 10-29-2010, 10:26 PM
  2. Pls help me connect my database sql and script
    By west10155 in forum Free Hosting
    Replies: 7
    Last Post: 08-09-2010, 03:48 AM
  3. how do i connect to mysql database from my script
    By elnasiru96 in forum Review My Site
    Replies: 3
    Last Post: 07-25-2010, 04:33 PM
  4. Replies: 2
    Last Post: 03-17-2010, 04:51 PM
  5. Replies: 0
    Last Post: 11-22-2008, 05:53 PM

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