Welcome to WebmasterWorld Guest from 3.231.226.211

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Parse error with mysql_select_db

     
11:42 pm on Jul 16, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 6, 2003
posts:630
votes: 0


I'm taking my first steps into the world of mysql and I've hit on an early problem.

When my (extremely simple) script tries to select the database I created, I get a parse error. The line i'm using is just:

mysql_select_db("testdb",$db);

Anyone have any suggestions as to what (probably obvious) error i'm making? It's driving me mad, because I want to play with my database :)

11:54 pm on July 16, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


assuming the name of the db is exact (case et al).

Lets see the mysql_connect as well. Also the resource link_identifier is an optional param, the function will assume the last opened link.

4:16 am on July 17, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 8, 2002
posts:65
votes: 0


If it's a simple script, I'm assuming you won't be connecting to more than once resource.

Which means you won't need the second parameter.

try
mysql_select_db("dbname");

"mysql_select_db() sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed."

edit: just as jatar_k said, I didnt notice his post.

9:59 am on July 17, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 6, 2003
posts:630
votes: 0


Thanks for the suggestions. I have a feeling I may be bombarding you guys with newbie database questions. Apologies in advance ;)

The parse error was a missing semi-colon in the previous line where I start the connection to the sql server (duh!) which in the cold light of day I noticed and remedied.

However, now I'm stuck with a different error:

No Database Selected

The line I'm using is still mysql_select_db("testdb",$db);

Surely I am selecting the testdb database? I do have more than one database set up, so I don't know if this would be affecting it.

Before I started working on mysql, I was pretty intimidated by the whole database idea. It seems I was right to be ;)

Thanks for any help or advice.

10:09 am on July 17, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 6, 2003
posts:630
votes: 0


Hey, scrub that last post, the problem was the username I was using to make the connection.

/off to play with databases :)

2:29 pm on July 17, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


glad you figured it out pixel_juice.

A good way to post about error messages is to post the exact error and then the offending line that is referenced by the error.

2:37 pm on July 17, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 6, 2003
posts:630
votes: 0


Thanks jatar_k :)

>>A good way to post about error messages is to post the exact error and then the offending line that is referenced by the error.

I did try I promise ;)

The first problem above mainly resulted from the error message referring to line 8 of my script, when the missing semi-colon was actually on line 6 so I didn't check out the preceeding code too carefully.

If you have a minute i'd really appreciate it if you could help me with my next problem. [webmasterworld.com]

I think me learning mysql is gonna be like configuring a personal firewall - very noisy in the beginning, and then goes quiet and just keeps ticking along in the background ;)