[PHP] ? simple solution for error resulting from upgrade to php5

2011-07-19 Thread Dr Michael Daly
Hi
is there a simple solution here, other than reverting to php4?
An upgrade from php5 to php5 has resulted in an error msg in this line:

if(  strlen($db_res ) > 0 ) {

I understand this is bec. php5 is object orientated. It says an
Object of class DB_result could not be converted to a string


This is the full function:


function pbcs_db_query( $q , $die_on_error=true, $ext_db_handle="" ) {
global $db_handle;
global $db_res;
global $query_logging,$PHP_SELF;
global $short_query_cache,$short_query_caching;

if( $ext_db_handle == "" )
$query_db_handle = $db_handle;
else
$query_db_handle = $ext_db_handle;

if( $short_query_caching && strlen( $q ) < 80 ) {
$db_res = $short_query_cache[str_replace(" ","",$q)];
if(  strlen($db_res ) > 0 ) {
//do_log("object.log","READ: ".$db_res);
//  $db_res->resetResultSet( 0 );
mysql_data_seek( $db_res->result , 0 );
//do_log("query.log",$PHP_SELF." - FROM-CACHE - ".$q);

return $db_res;
}
}



Thanks
Michael

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



Re: [PHP] ? simple solution for error resulting from upgrade to php5

2011-07-19 Thread Tamara Temple


On Jul 19, 2011, at 3:05 AM, Dr Michael Daly wrote:


Hi
is there a simple solution here, other than reverting to php4?
An upgrade from php5 to php5 has resulted in an error msg in this  
line:


if(  strlen($db_res ) > 0 ) {

I understand this is bec. php5 is object orientated. It says an
Object of class DB_result could not be converted to a string


This is the full function:


function pbcs_db_query( $q , $die_on_error=true, $ext_db_handle="" ) {
global $db_handle;
global $db_res;
global $query_logging,$PHP_SELF;
global $short_query_cache,$short_query_caching;

if( $ext_db_handle == "" )
$query_db_handle = $db_handle;
else
$query_db_handle = $ext_db_handle;

if( $short_query_caching && strlen( $q ) < 80 ) {
$db_res = $short_query_cache[str_replace(" ","",$q)];
if(  strlen($db_res ) > 0 ) {
//do_log("object.log","READ: ".$db_res);
//  $db_res->resetResultSet( 0 );
mysql_data_seek( $db_res->result , 0 );
//do_log("query.log",$PHP_SELF." - FROM-CACHE - ".$q);

return $db_res;
}
}


What does short_query_cache[] contain?



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



Re: [PHP] ? simple solution for error resulting from upgrade to php5

2011-07-19 Thread Dr Michael Daly
Hi
short_query_caching is referenced only once more in the script:


if( $query_logging )
do_log("query.log",$PHP_SELF." -  ".$q);

if (preg_match('/^\s*delete/i', $q)) {
  $p = $query_db_handle->prepare($q);
  if (DB::isError($p) && $die_on_error ) { die ("PREPARE:\n".$q .
"\n\n" . $p->getMessage() . "\n\n" . $p->getCode()); }
  $db_res = $query_db_handle->execute($p);
  if (DB::isError($db_res) && $die_on_error ) { die
("EXECUTE:\n".$q . "\n\n" . $db_res->getMessage() .
"\n\n" . $db_res->getCode()); }
} else {
  $db_res = $query_db_handle->query($q);
  if (DB::isError($db_res) && $die_on_error ) { die ($q .
"\n\n" . $db_res->getMessage() . "\n\n" .
$db_res->getCode()); }
}

// Let's cache all single row results and serve those cached values, if
// the query string matches exaclty.
if( $short_query_caching && is_object($db_res) && $db_res->numRows() == 
1
&& strlen($q) <= 80) {
//do_log("query.log","$PHP_SELF - CACHED $q");
$short_query_cache[str_replace(" ","",$q)] = $db_res ;
//  print "";
}

return $db_res;
}


Michael


On Jul 19, 2011, at 3:05 AM, Dr Michael Daly wrote:

> Hi
> is there a simple solution here, other than reverting to php4?
> An upgrade from php5 to php5 has resulted in an error msg in this
> line:
>
> if(  strlen($db_res ) > 0 ) {
>
> I understand this is bec. php5 is object orientated. It says an
> Object of class DB_result could not be converted to a string
>
>
> This is the full function:
>
>
> function pbcs_db_query( $q , $die_on_error=true, $ext_db_handle="" ) {
>   global $db_handle;
>   global $db_res;
>   global $query_logging,$PHP_SELF;
>   global $short_query_cache,$short_query_caching;
>
>   if( $ext_db_handle == "" )
>   $query_db_handle = $db_handle;
>   else
>   $query_db_handle = $ext_db_handle;
>
>   if( $short_query_caching && strlen( $q ) < 80 ) {
>   $db_res = $short_query_cache[str_replace(" ","",$q)];
>   if(  strlen($db_res ) > 0 ) {
>   //do_log("object.log","READ: ".$db_res);
> //$db_res->resetResultSet( 0 );
>   mysql_data_seek( $db_res->result , 0 );
>   //do_log("query.log",$PHP_SELF." - FROM-CACHE - ".$q);
>
>   return $db_res;
>   }
>   }

What does short_query_cache[] contain?





Dr Michael Daly MB, BS
GradDip(Integrative Medicine), GradCert(Evidence Based Practice),
M Bus(Information Innovation), GradDip(Document Management)
03 9521 0352
0413 879 029

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



Re: [PHP] ? simple solution for error resulting from upgrade to php5

2011-07-19 Thread Dr Michael Daly

Thanks Geert
That has fixed it, with flying colours!

Michael
On 19.07.2011, at 10:05, Dr Michael Daly wrote:

> Hi
> is there a simple solution here, other than reverting to php4?
> An upgrade from php5 to php5 has resulted in an error msg in this line:
>
> if(  strlen($db_res ) > 0 ) {

isn't this a simple check if $db_res is set?
what if you change it to -

if (is_object($db_res))

i would not downgrade to php4, but fix the code, it is not that much
trouble usually




Dr Michael Daly MB, BS
GradDip(Integrative Medicine), GradCert(Evidence Based Practice),
M Bus(Information Innovation), GradDip(Document Management)
03 9521 0352
0413 879 029

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



Re: [PHP] ? simple solution for error resulting from upgrade to php5

2011-07-19 Thread Daniel Brown
On Tue, Jul 19, 2011 at 04:05, Dr Michael Daly  wrote:
> Hi
> is there a simple solution here, other than reverting to php4?
> An upgrade from php5 to php5 has resulted in an error msg in this line:
>
> if(  strlen($db_res ) > 0 ) {

Change that to:

if (is_object($db_res)) {

> I understand this is bec. php5 is object orientated. It says an
> Object of class DB_result could not be converted to a string

Right.  Before, it was succeeding on `strlen($db_res) > 0`
because - like an array - when called as a string, it was evaluating
to its variable type.  For example:

 'per', 'doo' => 'per');
echo $a; // Prints: Array

$b = new fakeClass(); // Presuming this class exists
echo $b; // Used to print: Object id #1
?>

-- 

Network Infrastructure Manager
http://www.php.net/

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