I have a few simple lines of code to connect to a database from my web page, (code based on Kyank's tutorials). The code runs as follows:
<?php
// Connect to the database server
$dbcnx = @mysql_connect("localhost","-----", "-----");
if (!$dbcnx) {
echo( "<br>Unable to connect to the " .
"database server at this time." );
exit();
}
else echo ("Server connect... ok.");
// Select the projects database
$dbsel = @mysql_select_db("projects");
if (!$dbsel) {
echo( "<br>Unable to locate the project " .
"database at this time." );
exit();
}
else echo ("<br>Database connect... ok.");
?>
I get the "Server connect ok" line, but always receive the "unable to connect to projects database" line after.
I have double-checked the name of the database, the location certainly is correct, and I've even been able to modify the db with phpMyAdmin even when this code says the db is unavailable. Thus, I figure my code is buggy somehow, but I just can't see it.
Help, anyone? Thanx
The parameter that Karl suggests adding is optional, and should not be needed.
I can't see anything wrong with the code. Are you positive you've got the name of the database right down to the case (e.g. "Projects" instead of "projects")?
HA HA HA!!! total newbie mistake. "projects" is actually the name of a table within my database, not the database name itself. i fixed the call and now connect just fine. now all i have to do is figure how to work with the tables within a DB. :P
thanx all for your help.
Bookmarks