Page 1 of 1

conecting to db

Posted: Wed Dec 22, 2004 5:28 pm
by C_Calav
hi guys,

just finished getting everything set up at work and had a few problems with connecting to mySQL.

now that i can connect to mySQL, i cannot seem to select the database i want.

if i run myysql.exe i can select the db i want and run commands fine.

but when i run my script i get "Could not select database!");

Code: Select all

mysql_connect('localhost','chris','survey') or die ("Could not connect to database");

    mysql_select_db('survey') or die ("Could not select database!");



now one other query if anyone knows anything about is,

as i said before i had some problems connecting to MySql.

i went from:
$db = mysql_pconnect(......

with this error
Execution failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1
to

mysql_pconnect(......

and it worked. strange could some tell me whats going on thanx!

Posted: Wed Dec 22, 2004 5:49 pm
by Joe
use mysql_error() instead. By the looks of it your database name is either incorrect or localhost is not an available access host.

Posted: Wed Dec 22, 2004 5:54 pm
by raging radish
Try outputting the SQL error message to get a better indication of why:

Code: Select all

@mysql_select_db($dbase)
  or die ("Bloody script won't connect because: ".mysql_error());
print "Connected to dbase...";
Also, the database name is case sensitive.

Posted: Wed Dec 22, 2004 5:55 pm
by raging radish
Joe wrote:use mysql_error() instead.
Doh! You posted while I was writing.

Posted: Wed Dec 22, 2004 6:15 pm
by C_Calav
just had a lunch break came back to it with fresh mind all good now thanx guys..

never underestermate mysql_error()!