[PHP-DB] strange mysqli error
Good afternoon. I'm getting a weird mysqli error in my object destructor. Here's an example: ?php $db = new mysqli('localhost', USERNAME, PASSWORD, DATABASE); class Test { function __construct() { global $db; $db-query(SELECT 'test'); print_r($db-error); } function __destruct() { global $db; $db-query(SELECT 'test'); // line 20 print_r($db-error); // line 21 } } $test = new Test(); ? A. On my dev machine (Mac OS X + PHP 5.1.4 + MySQL 5.0.19) I get the following errors EVERY time: Warning: mysqli::query() [function.mysqli-query]: Couldn't fetch mysqli in /Users/richard/Projects/data/private/mgftest.php on line 20 Warning: Test::__destruct() [function.Test---destruct]: Couldn't fetch mysqli in /Users/richard/Projects/data/private/mgftest.php on line 21 B. On my production server (FreeBSD + PHP 5.1.2 + MySQL 5.0.19) I SOMETIMES get the following error: (If I refresh the page repeatedly, sometimes there's an error, sometimes not.) Warning: mysqli::query() [function.query]: Couldn't fetch mysqli in / usr/local/www/data/private/mgftest.php on line 20 C. On a commercial web host (PHP 5.0.4 + MySQL 5.0.22) I NEVER get any errors. There's nothing else in my error logs, $db-errno is 0, and $db-error is empty. Interestingly, I never get any errors from the constructor. Any ideas? Richard --- Richard K. Miller www.richardkmiller.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] In_Array in Query
I'm wondering if something like this is possible, where $array is an array. $query = select id from table where in_array(row,'$user_area'); Is it possible to see if the value of a particular row is in an array? I know I could create a loop where it would go through each one, but I was hoping not to do something like the following: $query = select id from table where row = $user_area[0] OR row = $user_area[1] OR row = $user_area[2] -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
Re: [PHP-DB] In_Array in Query
Kevin Murphy wrote: I'm wondering if something like this is possible, where $array is an array. $query = select id from table where in_array(row,'$user_area'); Is it possible to see if the value of a particular row is in an array? I know I could create a loop where it would go through each one, but I was hoping not to do something like the following: $query = select id from table where row = $user_area[0] OR row = $user_area[1] OR row = $user_area[2] Not really. There is a slight shortcut: $query = select id from table where row in ( . implode(',', $user_area) . ); which does much the same (your db converts it internally). That assumes 'user_area' only contains numbers, any strings in there and you'll have to create a loop so you can use the proper escaping function (depending on your db). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] In_Array in Query
not as sucj, but you could consider a sub-select (providiing your version of mysql supports it) something like this might also work $query = select id from table where somefield [in|=|like] (. in_array(row,'$user_area').); Bastien From: Kevin Murphy [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] In_Array in Query Date: Tue, 22 Aug 2006 18:13:11 -0700 I'm wondering if something like this is possible, where $array is an array. $query = select id from table where in_array(row,'$user_area'); Is it possible to see if the value of a particular row is in an array? I know I could create a loop where it would go through each one, but I was hoping not to do something like the following: $query = select id from table where row = $user_area[0] OR row = $user_area[1] OR row = $user_area[2] -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php