mySQL call for help
Ok, I’m just about to go insane here. I’m working on a little mySQL project, and I can’t even get as far as having the “application” (such as it is at all of just a few lines at the moment) to select the database.
I’ve connected to the database fine, but when it comes time to select a database, it dies. I’ve looked everywhere, but kind figure out why it would be happening.
Anyone run into this problem before? Have any suggestions? I’ve tried multiple varations on the following code:
$hostname = “localhost”;
$username = “USERNAME”;
$password = “PASSWORD”;
$dbName = “USERNAME_DATABASENAME”;
/* MySQL table created to store the data */
$userstable = “mytable”;
/* make connection to database */
mysql_connect($hostname,$username,$password) OR DIE(”Unable to connect to database”);
/* please note, I’ve also tried pconnect, either way, it connects to mySQL just fine… it’s the next line that dies out no matter what…. */
mysql_select_db($dbName) or die(”Unable to select database”);
I’ve also tried using the function: mysql_selectdb, I’ve tried having the reference to the db connection stored in a variable ($db) and then doing:
mysql_select_db($dbName, $db)
I’ve tried putting $dbName in qoutes, $db in quotes, putting an “@” symbol before mysql_connect or mysql_pconnect, or before mysql_select_db (I have no idea what the significance of the “@” symbol is…
AAaaaah! Going. Insane.
August 1st, 2002 at 12:40 pm
try this:
mysql_select_db($dbName) or die (mysql_error()) ;
That should give you the mysql error, and it might help. Also, the @ before a function supresses any error messages that might otherwise result. Also add the mysql_error() to the other mysql functions you use - it could be that the error is occuring before hand
August 1st, 2002 at 1:16 pm
Excellent! That does help a great deal. Apparently, it’s a problem with the user… it’s not giving that user access to the database (thought they had added that user to the database, but at least I know where to start looking to solve the problem).
Thank you!!!
August 1st, 2002 at 7:55 pm
Just putting this here for my future reference… to reset the auto-increment in a table, do this:
ALTER TABLE tbl_name AUTO_INCREMENT = 1;
August 2nd, 2002 at 9:13 am
Check out ‘grant’ here:
http://www.mysql.com/doc/A/d/Adding_users.html