Re: PEAR DB prepare function with postgresql
| From: | Dnorwood | Date: | Mon, 14 Jul 2003 18:34:23 +0000 |
| Subject: | Re: PEAR DB prepare function with postgresql | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-6587@lists.php.net to get a copy of this message | ||
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
>
>