Re: mysql_select_db error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 31 Oct 2004 00:19:12 -0400, Steven James Samuel Stapleton
<stapleton@xxxxxxxxxxxxxxxxxx> wrote:
> Relevant information:
> Windows XP Pro SP2
> PHP 5.0.2
> MySQL 4.0.21-nt
> command line (not server-side)
> 
> mysql_select_db returns no errors, and does not result in a mysql_error(),
> however, later queries result in errors suggesting that the switch failed:

No errors, that's correct, but it does return a boolean value.  So are
you testing that return value?

if( mysql_select_db('foo') !== true ) die('cannot select db');

> //I'm having problems with mysql_select_db("DBNAME", resource) and
> $test = mysql_query("use DBNAME", $resource);

You might want to try killing it right there with something like:

$test = mysql_query() || die('bad query: ' . mysql_error());

> //This results in no errors (I checked to make sure a true value was
> returned,

mysql_query() returns a resource handler, not a boolean value.

> //and made sure mysql_errno() returned 0).
> if(!$test || mysql_errno())
> {
>   die("Error selecting DB");
> }
> 
> //next, I'll make a query:
> mysql_query("create table foo ( bar int, morebar int )", $resource);
> if(mysql_errno())
> {
>   die(mysql_error());
> }
> //I get
> //No Database Selected

$test = mysql_query() || die('bad query: ' . mysql_error());


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux