Req #67213 [Opn->Fbk]: Add PDO::PARAM_DEFAULT constant
Edit report at https://bugs.php.net/bug.php?id=67213&edit=1
ID: 67213
Updated by: requinix@php.net
Reported by: public at gaxweb dot com
Summary: Add PDO::PARAM_DEFAULT constant
-Status: Open
+Status: Feedback
Type: Feature/Change Request
Package: PDO related
PHP Version: 5.5.12
Block user comment: N
Private report: N
New Comment:
What's wrong with
$sth = $dbh->prepare('INSERT INTO fruit (name, calories) VALUES(?,DEFAULT)');
$sth->bindValue(1, null, PDO::PARAM_NULL);
$sth->execute();
Or simply not including calories in the list of fields?
Previous Comments:
------------------------------------------------------------------------
[2014-05-06 11:33:31] public at gaxweb dot com
Description:
------------
It's currently not possible to bind the SQL DEFAULT keyword to a placeholder in prepared
statements like you can for NULL for example. This would be very helpful for prepared INSERTs (see
test script).
It'd allow for more flexible statements, since you wouldn't have to put DEFAULT into the
INSERT statement (
So please add a PDO::PARAM_DEFAULT constant. I'm not sure if, the value param of the
bindValue() method should actually matter.
Test script:
---------------
// The calories column has a default value set in the TABLE definition
$sth = $dbh->prepare('INSERT INTO fruit (name, calories) VALUES(?,?)');
// This is supported:
$sth->bindValue(1, null, PDO::PARAM_NULL);
// This isn't, but would be helpful:
$sth->bindValue(2, 'DEFAULT', PDO::PARAM_DEFAULT);
$sth->execute();
// actual query executed:
// INSERT INTO fruit (name, calories) VALUES(null, DEFAULT);
// notice the lack of quotes around DEFAULT
Expected result:
----------------
It should replace the 2nd placeholder with the literal keyword DEFAULT, and not put it in quotes.
Actual result:
--------------
It fails.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67213&edit=1
Thread (5 messages)