Req #67213 [Fbk->NoF]: Add PDO::PARAM_DEFAULT constant
| From: | php-bugs at lists dot php dot net | Date: | Tue, 30 Dec 2014 10:42:36 +0000 |
| Subject: | Req #67213 [Fbk->NoF]: Add PDO::PARAM_DEFAULT constant | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189482@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67213&edit=1
ID: 67213
Updated by: php-bugs@lists.php.net
Reported by: public at gaxweb dot com
Summary: Add PDO::PARAM_DEFAULT constant
-Status: Feedback
+Status: No Feedback
Type: Feature/Change Request
Package: PDO related
PHP Version: 5.5.12
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2014-05-07 09:54:05] public at gaxweb dot com
I thought I had addressed that. Like I said, this is not flexible. That way, you can only ever
insert the default value, not an actually different one. So you'd have to prepare both
statements (yours and mine) to make it work for both cases.
Imagine a loop, where for every execute() different values will be bound. I'd have to know the
column's default value beforehand to make use of my prepared statement without access to a
PDO::PARAM_DEFAULT constant. If the constant was available, I could just leave that up to the
database (less duplication).
------------------------------------------------------------------------
[2014-05-06 17:18:27] requinix@php.net
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?
------------------------------------------------------------------------
[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