placeholders.
The current restriction is that you may not use the same named parameter
more than one in a given query, as there is a danger of scary things happen
with the zval if it gets bound multiple times.
Allow drivers to add methods to dbh and stmt objects
(note that we can't use a class, because the use only sees the PDO class).
Clarify the api slightly:
PDO::exec() is used for one-shot queries that don't return rows
PDO::query() is a convenience function for returning a rowset without
having to go through the steps of preparing and executing.
PDOStatement::setFetchMode()
reset default fetch() mode for a statement to PDO_FETCH_BOTH
PDOStatement::setFetchMode(PDO_FETCH_NUM)
PDOStatement::setFetchMode(PDO_FETCH_ASSOC)
PDOStatement::setFetchMode(PDO_FETCH_BOTH)
PDOStatement::setFetchMode(PDO_FETCH_OBJ)
set default fetch() mode for a statement.
PDOStatement::setFetchMode(PDO_FETCH_COLUMN, int colno)
set default fetch() mode to retrieve colno-th column on each fetch() call.
PDOStatement::setFetchMode(PDO_FETCH_CLASS, string classname [, array ctor args])
set default fetch() mode to create an instance of classname,
calling it's ctor, passing the optional ctor args.
The names of the columns in the result set will be used as property names on
the object instance. PPP rules apply.
[NOTE: calling ctor is not yet implemented]
[TODO: this might crash PHP for persistent PDO handles]
PDOStatement::setFetchMode(PDO_FETCH_INTO, object obj)
Similar to PDO_FETCH_CLASS, except that each iteration will update the
supplied object properties.
[TODO: this might crash PHP for persistent PDO handles]
The default fetch() mode is used when no parameters are passed to
PDOStatement::fetch(). When using a statement in an iterator context,
PDOStatement::fetch() is called implicitly on each iteration.
object PDO::queryAndIterate(string sql, <PDOStatement::setFetchMode args>)
This is semantically equivalent to:
$stmt = $pdo->prepare($sql);
$stmt->execute();
$stmt->setFetchMode($args);
return $stmt;
Example/Intended usage:
/* fetch an array with numeric and string keys */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test") as $row) {
debug_zval_dump($row);
}
/* fetch the value of column 1 into $row on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_COLUMN, 1) as $row) {
debug_zval_dump($row); // string(3) "foo"
}
/* create a new instance of class Foo on each iteration */
foreach ($pdo->queryAndIterate("select NAME, VALUE from test",
PDO_FETCH_CLASS, 'Foo') as $row) {
debug_zval_dump($row);
/*
Object(Foo)#4 (2) refcount(2){
["NAME"]=>
string(12) "foo220051429" refcount(2)
["VALUE"]=>
string(12) "bar789825748" refcount(2)
}
*/
}
etc.
Add a uri: psuedo driver; it specifies the name of a resource that contains,
as its first line, the actual data source to connect to.
The resource can be a local file, or it can be any resource for which PHP
has a wrapper.
// loads connection data from the file "myapp"
$d = new PDO('uri:myapp');
// lets say that public.db.com has a read-only db open for the public
// their connection data is also published via the web:
// (not so great to resolve this on each request though...)
$d = new PDO('uri:http://public.db.com/pdo-connection-data');
Still more to come. Give it a couple of days before starting to write drivers
for the other databases; a few things might change, so I'd like to coordinate
that, but in a couple of days.