From: Eric Chamberlain <Eric.Chamberlain@zonarsystems.com>
To: Andy Shellam <andy-lists@networkmail.eu>
Cc: pgsql-php@postgresql.org <pgsql-php@postgresql.org>
Subject: Re: Stored procedures, PDO, and PHP issue
Date: Wed, 19 Aug 2009 15:25:25 -0700
Message-ID: <B6A537B5-C287-44CD-A8A2-265086D3DB4F@zonarsystems.com> (raw)
In-Reply-To: <4A8C6B7D.7020806@networkmail.eu>
References: <A11E730E-82D7-4EE6-AD80-ECD95982D78A@zonarsystems.com>
<4A8C6432.2050500@networkmail.eu>
<2AE0AB18-0F9D-4A32-92D3-4D86F176D432@zonarsystems.com>
<4A8C6B7D.7020806@networkmail.eu>
On a hunch I have solved the problem. You can not use the question
mark syntax and the cast. Instead you have to use the named
parameters with the cast.
$stmt->prepare("SELECT
is_password_expired(:user_id::INTEGER, :pass::VARCHAR);
$stmt->bindValue(':user_id', $userId);
$stmt->bindValue(':pass', $hashPass);
$stmt->execute();
Thank you all for your help! You guys are awesome!
For completeness I'd like to answer your questions:
My cohort grabbed this information somewhere from the PHP site:
These are the conversions PDO does during binding.
* PDO::PARAM_STR converts whatever you give it to a string
* PDO::PARAM_INT converts bools into longs
* PDO::PARAM_BOOL converts longs into bools
That's it. Nothing else is converted. PDO uses the PARAM flags to
format SQL not to cast data types.
This explains why it didn't correctly identify the correct proc to use.
> Hi Eric,
>
>>
>> Unfortunately this does not work or I maybe doing it wrong. New
>> code:
>> $stmt = $db->prepare("SELECT is_password_expired($1::integer,
>> $2::varchar);
>> $stmt->bindValue(1, settype($userId, "integer"), PDO::PARAM_INT);
>> $stmt->bindValue(2, $hashPass, PDO::PARAM_STR);
>> $stmt->execute();
>
> settype() doesn't return anything so it needs to be used on it's own
> line. E.g.:
That's very good to know! It still didn't work, but at least I
learned something new :)
> $userId = "2"; // string
> settype($userId, 'integer'); // $userId is now an integer
> $stmt->bindValue(1, $userId, PDO::PARAM_INT);
>
>>
>> I get a blank screen. I've tried setting the error reporting level
>> to:
>>
>> error_reporting(E_ALL);
>>
>> before calling the above code. Our servers are configured to display
>> errors, etc. The fact that it just goes blank tells me there is a
>> bigger issue going on.
>
> Does your server definitely have display_errors set to On as well as
> the
> error_reporting line, and it's not been overridden by your
> application?
> I've only ever known really serious errors (i.e. core dumps) to not
> display anything even when display_errors is set to on. What's logged
> in your Apache or IIS error log?
It does have errors displayed.
Here is what is in the Apache log:
[Wed Aug 19 15:07:02 2009] [notice] child pid 31897 exit signal
Segmentation fault (11)
[Wed Aug 19 15:07:03 2009] [notice] child pid 4163 exit signal
Segmentation fault (11)
[Wed Aug 19 15:07:05 2009] [notice] child pid 4122 exit signal
Segmentation fault (11)
[Wed Aug 19 15:07:07 2009] [notice] child pid 4209 exit signal
Segmentation fault (11)
This was after 5 successive hits using the ?::BIGINT, ?::VARCHAR syntax.
> Lastly have you tried "named" parameters? From the PHP manual:
> (actually the PostgreSQL syntax "$1::integer" I suggested may have
> caused PHP to crash as PDO uses a colon to introduce a named
> parameter.)
>
> |$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES
> (:name, :value)");
> $stmt->bindParam(':name', $name);
> $stmt->bindParam(':value', $value);|
Tried this. No go.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: Eric.Chamberlain@zonarsystems.com, andy-lists@networkmail.eu
Subject: Re: Stored procedures, PDO, and PHP issue
In-Reply-To: <B6A537B5-C287-44CD-A8A2-265086D3DB4F@zonarsystems.com>
References: <A11E730E-82D7-4EE6-AD80-ECD95982D78A@zonarsystems.com> <4A8C6432.2050500@networkmail.eu> <2AE0AB18-0F9D-4A32-92D3-4D86F176D432@zonarsystems.com> <4A8C6B7D.7020806@networkmail.eu> <B6A537B5-C287-44CD-A8A2-265086D3DB4F@zonarsystems.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox