|
Posted by Erwin Moller on 10/03/05 13:26
smorrey@gmail.com wrote:
> Assuming this...
> $_SESSION['db'] = new PDO(
> "pgsql:dbname=test;host=localhost",
> "biocoinadmin",
> "xxxxxxxxxx"
> );
>
>
> What is wrong with this (line breaks added for clarity)?
>
> $sql = "SELECT * FROM public.authinfo WHERE uid = '$uid'";
> if ($_SESSION['db']->fetchAll(
> $_SESSION['db']->query($sql)) > 0
> ){
> dosomething();
> }else{
> dosomethingelse();
> }
>
> I keep getting this error...
>
> Fatal error: Call to undefined method PDO::fetchAll() in
> /home/testcode/public_html/header.php on line 114
>
> This doesn't make sense, because every other query I issue on the DB
> seems to be working great. This is the first time anykind of fetch is
> used, and it should just let me know if there is any data at all, as a
> result of the query right? I'm not asking for anything specific just a
> yes or no as to whether that uid exists in the DB.
>
> Any advice here?
Hi,
I think your handle to the database breaks when the session is serialized
and saved between pages. The unserialized connection you use on the next
page is not a valid connection anymore. (This is no Java)
Solution: Do not store a databaseconnection in a session: Recreate it on
every page.
If you still worry about speed: Have a look at pg_pconnect().
It uses a permanent connection.
My experience with Postgres and starting a fresh databaseconnection are very
good. It is superfast. I never used pg_pconnect.
Regards,
Erwin Moller
Navigation:
[Reply to this message]
|