Can't select db using php

Category: Databases

reversemix
Asked:
2013-06-16 4:09 pm EST

Hits: 472
I wrote the following test php script which looks almost exactly like the tutorial but it keeps saying that it can't select the database. I check the db name and made sure it matched. What could be the problem?

<?php
$db_host = "localhost";
$db_user = "test";
$db_pwd = "test123";
$curr_db = "mysite_test";

/* Connecting, selecting database */
$con = mysql_connect( "$db_host", "$db_user", "$db_pwd" );

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db( $curr_db, $con ) or die("Could not select database");
?>

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

Scott
Staff
20,898 Points
2013-06-17 10:37 am EST
Hello reversemix,

I tested the exact code on my own server and was able to get in just fine. I then created a test user on your account, attached it to a database, and created a database connection script file. It also worked.

My guess is that there is something incorrect in the variables. Be sure that the datbase name includes your cpanel username as a prefix. For example, if your username for cPanel is userna5 and the database name is testdb, then the $curr_db variable in the script must be named userna5_testdb.

Altering the database name from that standard configuration did cause me to get the error you mentioned.

Best Regards,
Scott M

You must login before you can post a comment about this answer.

Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!