Re: Re: PEAR DB prepare function with postgresql

From: Date: Mon, 14 Jul 2003 22:48:20 +0000
Subject: Re: Re: PEAR DB prepare function with postgresql
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-6597@lists.php.net to get a copy of this message
My understanding is that PEAR::DB "fakes" the prepare for the sake of platform independence. In effect, PEAR simulates the prepare for postgresql databases (and probably others). I would be quite interested in the response you get back from the postgresql extension coders. Please pass it along. Best Regards. Martin Marques wrote:
how can this be done if, at least for what I have seen, there is on prepare/execute statements in the pgsql extensions? I have seen them in the Informix extensions though. Even farther: DB/pgsql.php doesn't have a prepare function, where DB/oci8.php does (ifx.php also doesn't, but at least it's in the TODO). Any thoughts? I have just sent a mail to the coders of the pgsql extension to see what are there thoughts about these functions that are missing in PHP. On Lun 14 Jul 2003 15:34, Dnorwood wrote:
I've solved the problem I was having calling prepare within a separate function. PHP passes Object parameters by value, which means that I was preparing a statement against a copy of my db connection object ($dbh), not the original. The resolution, of course, is to pass the db connection object by reference to the prepare (prep_ins_user) function. "Dnorwood" <dnorwood@visi.com> wrote in message news:20030709182014.22546.qmail@pb1.pair.com...
I'm encountering the following behavior with PEAR DB prepare and execute functions: This code works. The prepared statement executes as expected.
    // create sql statement string
    $ins_sql = 'INSERT INTO foo VALUES (?,?,?,?,?,?)';
    // prepare sql statements
    $ins_stmt = $dbh->prepare($ins_sql);
    $result = $dbh->execute($ins_stmt,$foo_values);
This code does not work.
     $ins_stmt = User::prep_ins_stmt($dbh);
     $result = $dbh->execute($ins_stmt,$foo_values);
Basically, if I put the prepare() function call in a separate function
     
that
returns the statement handle the execute will not work. The returned $result is like this: object(db_error)(7) { ["error_message_prefix"]=> string(0) "" ["mode"]=> int(1) ["level"]=> int(1024) ["code"]=> int(-8) ["message"]=> string(17)
     
"DB
Error: invalid" ["userinfo"]=> string(0) "" ["callback"]=> NULL } I've used gettype() and var_dump to ensure that the returned statement handle has the same value as the handle generated by the successfuly prepare() call in the sub function - int(0). However, the fact remains
     
that
I unless I call the prepare() function in the same function as the execute(), the execute() will fail. Has anyone seen this behavior before? Is this expected? Known? Thanks for you help. D
     


« previous php.pear.general (#6597) next »