Req #67213 [Com]: Add PDO::PARAM_DEFAULT constant

From: Date: Wed, 07 May 2014 09:54:06 +0000
Subject: Req #67213 [Com]: Add PDO::PARAM_DEFAULT constant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185685@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
 Comment by:         public at gaxweb dot com
 Reported by:        public at gaxweb dot com
 Summary:            Add PDO::PARAM_DEFAULT constant
 Status:             Feedback
 Type:               Feature/Change Request
 Package:            PDO related
 PHP Version:        5.5.12
 Block user comment: N
 Private report:     N

 New Comment:

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).


Previous Comments:
------------------------------------------------------------------------
[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


Thread (5 messages)

« previous php.bugs (#185685) next »