Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cannot select db

Status
Not open for further replies.

squarkman

Technical User
Mar 10, 2008
34
Hi Gurus,
I have a php opt-in system works perfectly. Next, I simply removed the one line that mailed the information to my email address and replaced it with the code below to get one step closer to adding data to my database thru the system after confirmation. I get an error. The only thing that could be wrong is in the code below. The name of the database is correct, the username and password are correct and I guess 'localhost' works since the error I get is "cannot select db".
-----------------------

$host="localhost";
$username="xxxxxx";
$password="xxxxxx";
$db_name="xxxxxxxxx";
mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name")or die("cannot select db");
mysql_query("INSERT INTO customer (name, sex)VALUES ('Robert','male')");
mysql_query("INSERT INTO customer (name, sex)VALUES ('Sally','Female')");
mysql_close($con);
 
Does the user you give has access rights to the DB? Note that "localhost" is not the same as "127.0.0.1" in mysql on linux.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
It's my database. It's not administrative but it is full access.
 
Add error checking to your mysql calls.

Code:
mysql_connect("$host", "$username", "$password") [red]or die(mysql_error())[/red];
mysql_select_db("$db_name")or die([red]mysql_error()[/red]);

Perhaps it will be more meaningful than your custom message.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Great idea. Thanks! I'll give it a try.

You know, this MySQL connectivity issue is vexing to me.

I have have to f around for hours with connectivity problems EVERY time I mess with MySQL. There needs to be some kind of simplification of this in my opinion, or a good way to troubleshoot it.

Could it be that $host should not be localhost? I wouldn't know what the correct url to the server would be anyway.

I cannot get TELNET to work but if I could maybe that would help. I did download a connection to for SQL software from White Peak Software and this is the error I get.

[Microsoft][ODBC SQL Driver][DBNETLIB]SQL Server does not exist or access denied. [Micorsoft}[ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).

Any thoughts please?
Thx
 
After I changed the error statement, here is the new details.

Access denied for user: 'squarl@localhost' (Using password: YES)

I guessed that access was denied. Too bad it couldn't tell me why, lol

What does
Using password: YES mean?

Thx
 
It means that you were using a password.

Anyway looks like the user you are trying to connect as does not have rights to connect to the DB. Or at least not from that location.

Where is your DB located, is it in the same machine as the Webserver and PHP or in a different one? Te only time that can be locahost is if they are in the same server.
Otherwise it should be either an IP address or a web URL

Now for the user permissions. Make sure you gave that user adequate permissions to access the database and from that location.

Using the MYSQL Administrator GUI it should a be a simple matter of checking the correct permissions.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I am the administrator and the only user.
I just created the databases gave full access to all and setup the username and passwords thru the Admin GUI.

I have heard something about registering databases but not sure what that is

Also there is an ODBC setup with each database but have left that blank.

It's all the same server from my perspective.

A pretty simple scenario but problematic, eh?

Hmm


 
I believe there is an option to add a location to each user from the GUI. I don't have access to a mysql admin gui right now, but if you right click on the user I think it should give you the option. just add localhost as the location. You will need to add all the actions to the user from that location. SELECT, INSERT, UPDATE etc...

Its somewhat annoying I know. but for web development and mysql logging in as a user like root, is different than logging in as a user in a location like root@localhost.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Just like there's a PHPINFO, is the an MySQLINFO? If not, why not?
Thnx
Rocky
 
Ok, now I'm getting angry...
Check this out.
I found this statement to get the path to MySQL
----------

echo `whereis mysql`;


The response I got to the path request and subsequent request to open the database:

mysql: /usr/local/mysql //Wow...looks like that's the path
Unknown MySQL Server Host '/usr/local/mysql' (1) //Nope, I've been dupe again!

This is crazy.
Can anyone tell me what's going on?
What does this have to be this difficult?
R
 
Suspect that 'whereis' may be looking at a config file somewhere. That doesn't mean that your server is actually running. Have you had a look in Control Panel|Administrative Tools|Services to make sure the MySQL server is currently running?

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
We can close out this one. I figured it out. I was on the wrong server.
Thanks
 
Woops. Spoke too soon. That didn't make any difference. Still can't find the database.
I'm ready to give up on MySQL piece of crap. Figures it's from Microsoft.
 
what? mysql is opensource and has nothing to do with microsoft.


 
No it doesn't. Many people including myself work fine off of it.

This is all coming down to a user permission issue.

You said this was your database. it looks to me that its on some kind of webhost. I thought you had local access to the db and could run mysql Adminsitrator app. not a Web DB management suite.

Anywho, from the Account Management option you have in that suite there, there should be an option to add a location to the user you want to connect as. Can you perhaps post a screen shot of the Account Management option. So we can see what it looks like?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I have checked the permission for all user. They are clearly
FULL ACCESS.
I'll check the Account Managment but I believe that's my billing address and other accounting info.
I'll post an shot of that for you.
Thanks
 
Of course I can't get in. I can loging to the damn Control Panel but cannot open the Account Management. I'll have to email tech support to fix all this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top