What do you mean with 'stops working'?

Also, have you created a test-script that only contains (what you think is)
the core-problem? If so, can you paste it here? And if not, i advise you to
make one, so you can exclude that other factors play a role here.


Thodoris wrote:
Hi list,
I am developing something using PDO and I've noticed something weird that I want to share with you. I am creating a database handler in a script and I pass the handler to many functions I use in order to avoid creating a new connection into the function itself. Although this works in a compiled LAMP I have, this stops working when I use a prepackaged version of another LAMP I have.

If I change the script in the non-working system and make the connection from inside the function using a new handler then everything works like a charm.

Is there a chance that I am using a different configuration in say php.ini that can cause such behavior.

Let me know what you think.

--
Thodoris


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





-----
http://devshed.excudo.net http://devshed.excudo.net


Suppose I have two tables Contracts and Clients that are connected using ClientId field.

This is a stripped sample code that doesn't work:

<?php


function getClientFullName($id,$dbh){


   $query = "SELECT * FROM Clients WHERE Id=".$id;

   $sthr = $dbh->query($query);


   $res = $sthr->fetch(PDO::FETCH_ASSOC);


   return $res['Name'];


}


try {

$dbh = new PDO('mysql:host=localhost;port=3306;dbname=ins', 'root', '', array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR_PERSISTENT => true));


   $sql = "SELECT * FROM Contracts";

   $sth = $dbh->query($sql);


   print "<pre>";


   while($res = $sth->fetch(PDO::FETCH_ASSOC)) {

       $name = getClientFullName($res['ClientId'],$dbh);

       print $name."<br>";

   }

} catch (Exception $e) {

   print $e->getMessage();

}

?>

And when I say it doesn't work I mean that that I get:

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


When calling:     getClientFullName


BTW try to top post.

--
Thodoris

Reply via email to