pascalc Posted June 26, 2008 Share Posted June 26, 2008 I'm new to php and MySql, and recently starting using phpMyAdmin on Yahoo. I created a new database (TestDB) and a 'login_table' with only 3 columns - loginID, password, and emal_address, and inserted 1 row. I inserted a new user in the user table on the MySql database for my php scripts - 'pcscript', and gave it select, insert, update, and delete privileges to TestDB. I use the following simple code to try to connect to the database: <? $con = mysql_connect("mysql", "pcscript", "password123"); if (!$con) { die('Could not connect: ' . mysql_error()); } @mysql_select_db("TestDB") or die("Cannot select DB!"); mysql_close($con); ?> I get the following error message: "Could not connect: Access denied for user 'pcscript'@'localhost' (using password: YES)". Even though the user 'pcscript' was created under the MySql host, but the error refers to 'pcscript@localhost'. Why can't I connect? Very frustrated. Please help. Pascal Quote Link to comment Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 some server setups have prefixes added to user names and database names. A common setup is for instance, if you owned www.mycoolsite.com and your assigned account name is mycoolsi that could be the prefix followed by an underscore followed by your username: mycoolsi_pcscript. same with the database name: mycoolsi_testdb. You want to talk to your host or read their documention to find out if they add some kind of prefix. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 26, 2008 Share Posted June 26, 2008 Also do bear in mind that a lot of shared, re-seller and virtual dedicated hosting plans have prefixes of usually the username which it has been registered with, as Crayon Violent said, however with prefixes, database names you enter tend to get cut off. This has often been my problem in the past, I've known about the database prefixes, however I've sometimes assumed that the whole name I entered would be used which wasn't the case. On a side note, most web hosting services provide local MySQL servers. And therefore you would need to enter "localhost" for the server address. e.g. $con = mysql_connect("localhost", "pcscript", "password123"); Quote Link to comment Share on other sites More sharing options...
pascalc Posted June 26, 2008 Author Share Posted June 26, 2008 Thanks for the response, but it wasn't the prefixes. I just deleted the user, and inserted him again with 'localhost' as the host, even though the script refers to 'MySql' as the host. That was confusing to me. It's working now. Thanks. Pascal I have a feeling I'll be back soon... Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 26, 2008 Share Posted June 26, 2008 Please mark the topic solved. Quote Link to comment Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 On a side note, most web hosting services provide local MySQL servers. And therefore you would need to enter "localhost" for the server address. I almost mentioned that but then I just figured he put something generic in there like most people do with host/name/pw when showing code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.