Re: [PHP] Weird pdo-mysql behavior
Perhaps when you try to make the connection you should check the return value and use whatever PDO error-checking methods exist to find out what went wrong, instead of blindly going forward assuming you have a database connection when you don't. As a said before I have dumped the hander and all the params before passing them into the function and the object has been crated. As I said the exact same code works in the same system using a different (compiled) apache and a different (compiled) version of PHP without any problems. It also works in another system using a compiled apache and PHP. Ditto for any result of ->query() What you are doing now is akin to turning the key in a car, not listening to see if it started, and asking a mechanic on the phone why the gas pedal doesn't work... :-) So I will have to assume that the rpm is not behaving as expected or that there is a bug in that specific version of PHP. -- Thodoris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird pdo-mysql behavior
I agree, add some checks in your testcase so you can track exactly what is happening and see of what type your variables are. Also, try what happens when you - switch off persistent-connections (PDO::ATTR_PERSISTENT=> false) Tried that using both ways because I saw a similar error in another bug in PHP but still doesn't fetch the data. - pass the object by reference (getClientFullName($id,&$dbh)) Also did that without making any difference. I am wondering if this has to do with PHP itself or with the way my distro is distributing the package. - http://devshed.excudo.net http://devshed.excudo.net Thanks anyway though for the suggestions. -- Thodoris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird pdo-mysql behavior
I agree, add some checks in your testcase so you can track exactly what is happening and see of what type your variables are. Also, try what happens when you - switch off persistent-connections (PDO::ATTR_PERSISTENT=> false) - pass the object by reference (getClientFullName($id,&$dbh)) - http://devshed.excudo.net http://devshed.excudo.net -- View this message in context: http://www.nabble.com/Weird-pdo-mysql-behavior-tp20478083p20496495.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Weird pdo-mysql behavior
Perhaps when you try to make the connection you should check the return value and use whatever PDO error-checking methods exist to find out what went wrong, instead of blindly going forward assuming you have a database connection when you don't. Ditto for any result of ->query() What you are doing now is akin to turning the key in a car, not listening to see if it started, and asking a mechanic on the phone why the gas pedal doesn't work... :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird pdo-mysql behavior
Hi Theodoris First place I'd look is to see if the sql query was successful. If it failed you'll get this error. You can try a simple test $sth = $dbh->query($sql); if ($sth == FALSE) { print "failed"; exit; } Arno Thanks for the advice but the script works in one of the other systems (running PHP 5.2.x) as well as in the same system using another apache and a different php that is compiled from source and not installed as an rpm package. The query itself works very good but the basic problem is that the $dbh handler probably doesn't get into the getClientFullName properly. If I dump the handler and the $id before calling getClientFullName it seems that their contents are as expected but when this function calls fetch on the handler it fails. I suspect that either PHP version 5.1.6 has a bug on this (but I could find something similar in bugs.php.net) or my distro's package is compiled like... -- Thodoris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Weird pdo-mysql behavior
Suppose I have two tables Contracts and Clients that are connected using ClientId field. This is a stripped sample code that doesn't work: 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 ""; while($res = $sth->fetch(PDO::FETCH_ASSOC)) { $name = getClientFullName($res['ClientId'],$dbh); print $name.""; } } 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 -- Hi Theodoris First place I'd look is to see if the sql query was successful. If it failed you'll get this error. You can try a simple test $sth = $dbh->query($sql); if ($sth == FALSE) { print "failed"; exit; } Arno -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird pdo-mysql behavior
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: 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 ""; while($res = $sth->fetch(PDO::FETCH_ASSOC)) { $name = getClientFullName($res['ClientId'],$dbh); print $name.""; } } 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
Re: [PHP] Weird pdo-mysql behavior
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 -- View this message in context: http://www.nabble.com/Weird-pdo-mysql-behavior-tp20478083p20478667.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Weird pdo-mysql behavior
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