Re: [PHP] mysql_select_db problem
oops, i forgot a @ for mysql_connect() but oh well, you get the point :) Regards, Philip Olson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_select_db problem
> The following code always returns the "Couldn't select > database" error. > $db_name="mydb"; > $table_name="my_table"; > $connection = @mysql_connect("localhost", "user", "password") or die > ("Couldn't connect."); > $db = @mysql_select_db($db_name) or die ("Couldn't select database"); > ?> Add some useful debugging: if (!$conn = mysql_connect($host, $user, $pass)) { print "Cannot connect to DB : " . mysql_error(); exit; } if (!@mysql_select_db($dbname)) { print "Cannot select DB ($dbname) : " . mysql_error(); exit; } The key here is mysql_error(). You could also use this function within your 'or die()' but personally I frown upon using 'or' like this, it's rather limiting. In the above, we are checking if the function returns false and if it does we do stuff, like print mysql_error() and exit the script. Do as you wish. On a related note, if you removed the '@' from your code, odds are it'd shout an error too. '@' can be useful for supressing errors so we can implement our own form of error management/trapping, like in the above. Regards, Philip Olson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_select_db problem
I use the following code for connection and selecting databases: $link = mysql_pconnect("localhost",$_SESSION['dbauser'],$_SESSION['dbapassword']) or die("Could not connect"); print "Connected successfully"; mysql_select_db("stamps") or die("Could not select database"); This works. Regards Peter Goggin - Original Message - From: "PossumPal" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, June 03, 2002 4:40 AM Subject: [PHP] mysql_select_db problem Hi, I'm a newbie, so please have mercy on my silliness... I've checked my formats, and can't seem to understand why I can connect to the db, but not select the db that I want to use. The following code always returns the "Couldn't select database" error. If I use the mysql monitor, I can select the database directly without any problems. Could someone point out what I'm missing? Regards, Carol -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_select_db problem
Do some error checking. You're turning off all the errors produced by the mysql statements, so how are you supposed to know what's wrong? You could also try: $db = mysql_select_db($db_name) or exit(mysql_error()); I'm not sure if mysql_error works for selecting the db, but it couldn't hurt to try :-) Cheers, # Nathan - Original Message - From: "PossumPal" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, June 02, 2002 12:40 PM Subject: [PHP] mysql_select_db problem Hi, I'm a newbie, so please have mercy on my silliness... I've checked my formats, and can't seem to understand why I can connect to the db, but not select the db that I want to use. The following code always returns the "Couldn't select database" error. If I use the mysql monitor, I can select the database directly without any problems. Could someone point out what I'm missing? Regards, Carol -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql_select_db problem
Hi, I'm a newbie, so please have mercy on my silliness... I've checked my formats, and can't seem to understand why I can connect to the db, but not select the db that I want to use. The following code always returns the "Couldn't select database" error. If I use the mysql monitor, I can select the database directly without any problems. Could someone point out what I'm missing? Regards, Carol
Re: [PHP] mysql_select_db() problem
> > What do you get if you use error checking? > > Well, that seems to be it, I'm getting 'Access deneid to user > '@localhost'. > > I'm talking to a guy on the mysql list, apparently it is a > phenomememememememmemonmmm that when you GRANT ALL using wildcards it > tends to grant all on * except localhost! It's not so much a "phenomememememememmemonmmm" as a deliberate design feature. On multi-user machines and network servers it is very common to have a security layer allowing tasks to only/not be performed on the 'system console'. For example, would you want a remote user to bring down a mainframe with some sort of STOP command? If you were an ISP or a DB Service Provider, would you want one user (using only one table, or one database) to be able to reboot the entire MySQL server (and affect all the other users/user-tables/user-databases)? Thus Fred@localhost is not the same privilege profile as Fred@somewhere-else to enable flexibility in access/security - even if Fred is the only user to ever touch the system! You have figured out by now, that to give Fred the same privileges on the server as from a client machine, they need to be GRANTed 'twice'. Looking at it the other way, such 'security' controls can be either limited by the user location, or by the name of the user, or by both! Regards, =dn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_select_db() problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 * and then Lars Torben Wilson declared > I take it that the connection worked fine? (Yeah, dumb question, but you > never know.) Yeah, all is well as far as connections concerned. > What do you get if you use error checking? Well, that seems to be it, I'm getting 'Access deneid to user '@localhost'. I'm talking to a guy on the mysql list, apparently it is a phenomememememememmemonmmm that when you GRANT ALL using wildcards it tends to grant all on * except localhost! - -- Nick Wilson Tel:+45 3325 0688 Fax:+45 3325 0677 Web:www.explodingnet.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) iD8DBQE8ZcMsHpvrrTa6L5oRAqyCAKChAKKFljtpKg+vKArgbLW6KwT2CQCeM5xc tRuUnNm8WUGOl8M7l1xrXfU= =xr5Z -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_select_db() problem
On Sat, 2002-02-09 at 12:24, Nick Wilson wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi all, > I just can't see what could possibly be wrong with my php here: > > $sel_db=mysql_select_db("mydb") or die > ("could not get the bugger"); > exit; > > I can 'USE mydb' just fine from the command line so what's the problem? > (returns the die statement) > > Much thanks.. > - -- > > Nick Wilson I take it that the connection worked fine? (Yeah, dumb question, but you never know.) What do you get if you use error checking? if (!$dbh = mysql_connect(. . .)) { echo "Could not connect; reason was " . mysql_error() . "\n"; return false; } if (!$sel_db = mysql_select_db('mydb', $dbh)) { echo "Could not select database '$sel_db'; reason was " . mysql_error() . "\n"; return false; } i.e. what do you get if you use mysql_error() after this fails? Torben -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_select_db() problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 * and then Jeff Sheltren declared > It may be having a problem because you are not specifying which > connection to use. > > perhaps try something like this: > > if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpasswd")) > die("An Error Occured. Unable to connect to the database."); > if(!@mysql_select_db("$dbname",$db)) > die("An Error Occured. Unable to find the database $dbname on the > MySQL server."); No, that's not it. If you don't specify a link id then it assumes the last connection or trys to establish one. (I've tried it anyway :-) Come on guys, someone must be able to spot the 'gotcha'! - -- Nick Wilson Tel:+45 3325 0688 Fax:+45 3325 0677 Web:www.explodingnet.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) iD8DBQE8ZYz6HpvrrTa6L5oRAtwcAJ9FTvFFc57I7lUs8euOPp42nc6dZwCeMmis UK+HqUaQ6fJlMUFWOlVsMZ8= =ymec -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_select_db() problem
It may be having a problem because you are not specifying which connection to use. perhaps try something like this: if(!$db = @mysql_connect("$dbhost", "$dbuser", "$dbpasswd")) die("An Error Occured. Unable to connect to the database."); if(!@mysql_select_db("$dbname",$db)) die("An Error Occured. Unable to find the database $dbname on the MySQL server."); Hope that helps. Jeff At 09:24 PM 2/9/2002 +0100, Nick Wilson wrote: >-BEGIN PGP SIGNED MESSAGE- >Hash: SHA1 > >Hi all, >I just can't see what could possibly be wrong with my php here: > > $sel_db=mysql_select_db("mydb") or die > ("could not get the bugger"); > exit; > >I can 'USE mydb' just fine from the command line so what's the problem? > (returns the die statement) > >Much thanks.. >- -- > >Nick Wilson > >Tel:+45 3325 0688 >Fax:+45 3325 0677 >Web:www.explodingnet.com > > > >-BEGIN PGP SIGNATURE- >Version: GnuPG v1.0.6 (GNU/Linux) > >iD8DBQE8ZYWRHpvrrTa6L5oRArthAJ9Vew5DIKSR7qzc4M2abhxJfpz5TwCfRmZJ >ZBn2oUXT4UgsH1hM/UyyNGs= >=ajT+ >-END PGP SIGNATURE- > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql_select_db() problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi all, I just can't see what could possibly be wrong with my php here: $sel_db=mysql_select_db("mydb") or die ("could not get the bugger"); exit; I can 'USE mydb' just fine from the command line so what's the problem? (returns the die statement) Much thanks.. - -- Nick Wilson Tel:+45 3325 0688 Fax:+45 3325 0677 Web:www.explodingnet.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) iD8DBQE8ZYWRHpvrrTa6L5oRArthAJ9Vew5DIKSR7qzc4M2abhxJfpz5TwCfRmZJ ZBn2oUXT4UgsH1hM/UyyNGs= =ajT+ -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php