Well, I'm not a total dunce, but this is the first time I am using MySQL and phpMyAdmin so maybe I just dont get something. In fact I must not get something, because I am able to log in to MySQL, but my script "mysql_select_db" is not finding the database I set up in phpMyAdmin.

Bless you for your help oh great community! IAAR at your mercy.

Here is all the relevant data:

My Host: JV-Hosting.net
PHP ver: 4.3.4
PHPinfo: http://jv-admin.net/phpinfo.php
MySQL ver: 4.0.18-standard
My Host User Name: wjames
MySQL User: wjames@localhost

Host Software I am Using:
Cpanel X (although seperately listed as 8.7.0 ?? - not really important)
MySQL AccountMaintenance (part of Cpanel)
phpMyAdmin

Here is what the Cpanel and phpMyAdmin has to say about my databases:

MySQL User: wjames_wjames

(this is the user name I created in the MySQL AccountMaintenance tools)
(I gave it the name "wjames" and it stuck that on the end of "wjames_")

MySQL Database: wjames_headshots
(again I gave it the name "headshots" and the Cpanel stuck it on to "wjames_")

phpMyAdmin reports the same names. There are no tables in the database "wjames_headshots".

Here is my PHP code:
<?php
$user="wjames_wjames";
$password="**********";
$database="wjames_headshots";
$link = @mysql_connect(localhost,$user,$password) or die ("Unable to connect");

$db_list = mysql_list_dbs($link);

while ($row = mysql_fetch_object($db_list)) {
echo $row->Database . "\n";
}

@mysql_select_db($database) or die( "Unable to select database");

mysql_close();
?>

end php

The code returns no list of databases and the select_db function dies.

When I have switched the user name to just "wjames" it fails to connect!

I have also tried selecting the database "headshots" without the "wjames_" but that also fails.

So, I am totally stumped!

Thanks Alot!
Atomic

    You say you're using Cpanel.
    Well, go to mysql Databases and check there if the username/database you are using are the same like the one listed there
    And don't forget that you must ADD a user to a database before you can use that user on that database🙂

      So I saw the button "Add User to DB"

      And bingo!

      So the problem was, I had created a database, and I had created a user. But I never added the user and its permissions to the database (actually I thought this happened when I created the database for some reason).

      And the tools dont report that there are "none" users associated with the database. Oh well. Worked it out, and I hope this posting helps some other Newbie in the future.

      Atomic

        Write a Reply...