Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010

    Unanswered: Could not connect:

    Dear all,

    me new to PHP/ MySql.

    I have the following code:

    $con = mysql_connect("localhost","my_db","") or die('Could not connect: ' . mysql_error());
    // create Database
    $qResult = mysql_query("CREATE DATABASE my_db",$con) or die('Database created...... '.mysql_error());
    // echo "Database created";
    // Create table
    mysql_select_db("my_db", $con) or die ("MySQL crapped out with:".MySQLErrNo()." ~ ".MySQLError);

    $sql = "CREATE TABLE Persons
    FirstName varchar(15),
    LastName varchar(15),
    Age int

    // Execute query
    $qResult = mysql_query($sql,$con) or die ("Failed to create table: ".MySQLErrNo()." ~ ".MySQLError);


    it gives the following error:

    Could not connect: Access denied for user 'my_db'@'localhost' (using password: NO)

    How to know the password of my database?

    What willl be the default password for root?


    Muhammad Nadeem

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    look at the manual for MySQL permissions
    its never a smart idea to run PHP scripts with the userid of 'root'
    its never a smart idea to have a null password for any user, especially user 'root'

    best thing to do in my books is to download the MySQL GUI tools which includes MySQL Administrator and MySQL Query Browser from the MySQL website. you can set permissions easily using the MySQL administrator program.

    its also a useful way of knowing that basic things like userid's permissions and so on area ll working before tearing your hair out in a PHP or other script
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Oct 2010

    Thanks For The Idea

    I am new to the php and thanks to you giving some tips that is useful and helpful. keep posting more tips thanks!!!!

  4. #4
    Join Date
    Nov 2010


    follow the advise above.. look it up in the manual for permissions..
    and also, I would advise that you store the connection variables on a different file and just include it in. (it would be easier to change variable parameters later on)
    If your the admin of that database, I would also suggest that you create a new user with passwords and grant it only with the permissions needed for that task.

Tags for this 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