Re: Re: Cannot create statement handler

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

 





Thodoris wrote:
I was wondering if anyone sees something I am bypassing:

I have this sample code that works in another server:

<?php

function getClientFullName($dbh,$id){
   // die(var_dump($dbh));
   $sql = "SELECT * FROM Clients WHERE Id=".$id;
   // die(print $sql);
   $sthr = $dbh->query($sql);
   // die(var_dump($sthr));
   $res = $sthr->fetch(PDO::FETCH_ASSOC);

   return $res['Name'];

}

try {
$dbh = new PDO('mysql:host=localhost;port=3306;dbname=ins', 'root', '', array(PDO::ATTR_PERSISTENT => false));

   $sql = "SELECT * FROM Contracts";
   $sth = $dbh->query($sql);

   print "<pre>";

   while($res = $sth->fetch(PDO::FETCH_ASSOC)) {
       $name = getClientFullName($dbh,$res['ClientId']);
       print $name."<br>";
   }
} catch (Exception $e) {
   print $e->getMessage();
}
?>

but in my case I can't make it work on my own server. I have removed both PHP and apache and compiled everything for source just to make sure that I will avoid possible problems using rpm. It seems that if I dump $sthr it returns false.

Although if I print the query and use it directly it works fine.

Apache 2.2.10
PHP 5.2.6
Linux EL5

I've posted this some days ago but none had any idea about this. Do think this could be a bug?


obvious but:
do a phpinfo() and check PDO is installed on the failing server
check db is on the failing server
check mysql is running on the failing server
check username and pass are correct for db
check username and pass combo can access via localhost



Yes all that are true because I am able to run a i simple query and retrieve the data normally. Not to mention that I double checked this. But when passing the database handler into a function then I get the results I mentioned before:

Call to a member function fetch() on a non-object



Nonetheless it is a good tip since someone can fail look in to the obvious.


At last I have found what the problem was. It was more of a mysql configuration problem than PHP. I needed to activate MySQL's buffered queries that I was not aware that defaults to non-active in my configuration.

I saw a relative bug that suggested this so the only thing that I should do was:

$dbh = new PDO('mysql:host=localhost;port=3306;dbname=xxx', 'xxx', 'xxx', array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY=>true));

So I probably got stuck to the *obvious*.


--
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