conecting to db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

conecting to db

Post 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!
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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.
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post 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.
raging radish
Forum Commoner
Posts: 32
Joined: Sun Nov 14, 2004 3:02 pm
Location: Toronto

Post by raging radish »

Joe wrote:use mysql_error() instead.
Doh! You posted while I was writing.
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

just had a lunch break came back to it with fresh mind all good now thanx guys..

never underestermate mysql_error()!
Post Reply