Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions PDO/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,9 @@ final function PDO()
$opts = array();
if (!empty($dsn_ar['fragment'])) {
// options.. |MYSQL_ATTR_INIT_COMMAND=....|
$pdo_rc = new ReflectionClass( "PDO" );
foreach(explode('|', $dsn_ar['fragment']) as $opt) {
list($k,$v) = explode('=', $opt);
$opts[$pdo_rc->getConstant($k)] = $v;
$opts[self::dsnOptionConstant($k)] = $v;

}
}
Expand Down Expand Up @@ -654,6 +653,35 @@ final function PDO()
return self::$connections[$md5];
}

/**
* Resolve a PDO option constant by name, as used in DSN fragment options
* (eg. |MYSQL_ATTR_INIT_COMMAND=...|).
*
* Driver-specific constants (MYSQL_*, PGSQL_*, SQLITE_*, OCI_*, ODBC_*, DBLIB_*, FIREBIRD_*)
* are deprecated on the base PDO class since PHP 8.5 - resolve them via the Pdo\<Driver>
* subclasses (available since PHP 8.4) when possible, falling back to the PDO class
* for generic constants and on older PHP versions.
*/
private static function dsnOptionConstant($name)
{
static $driverClasses = array(
'MYSQL' => 'Pdo\\Mysql',
'PGSQL' => 'Pdo\\Pgsql',
'SQLITE' => 'Pdo\\Sqlite',
'OCI' => 'Pdo\\Oci',
'ODBC' => 'Pdo\\Odbc',
'DBLIB' => 'Pdo\\Dblib',
'FIREBIRD' => 'Pdo\\Firebird',
);

foreach ($driverClasses as $prefix => $class) {
if (strpos($name, $prefix . '_') === 0 && defined($class . '::' . $name)) {
return constant($class . '::' . $name);
}
}

return defined('PDO::' . $name) ? constant('PDO::' . $name) : false;
}



Expand Down Expand Up @@ -3378,9 +3406,15 @@ final function query($string)
return $this->raise("Could not run Query: " . $result->getMessage(), self::ERROR_QUERY, $result);
}

// PDO::MYSQL_ATTR_USE_BUFFERED_QUERY is deprecated since PHP 8.5 in favor of
// Pdo\Mysql::ATTR_USE_BUFFERED_QUERY (only available from PHP 8.4 onwards).
$mysqlAttrUseBufferedQuery = defined('Pdo\\Mysql::ATTR_USE_BUFFERED_QUERY')
? constant('Pdo\\Mysql::ATTR_USE_BUFFERED_QUERY')
: PDO::MYSQL_ATTR_USE_BUFFERED_QUERY;

switch (true) {
case $dbtype == 'sqlite':
case $pdo->getAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY) == 0:
case $pdo->getAttribute($mysqlAttrUseBufferedQuery) == 0:
$no_results = true;
break;

Expand Down
1 change: 1 addition & 0 deletions PDO/DataObject/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
*

*/
#[AllowDynamicProperties]
class PDO_DataObject_Cast {

/**
Expand Down
1 change: 1 addition & 0 deletions PDO/DataObject/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/


#[AllowDynamicProperties]
class PDO_DataObject_Exception extends Exception
{

Expand Down
1 change: 1 addition & 0 deletions PDO/DataObject/Generator/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @version 1.0
* @link https://github.com/roojs/PDO_DataObject
*/
#[AllowDynamicProperties]
class PDO_DataObject_Generator_Column
{

Expand Down
1 change: 1 addition & 0 deletions PDO/DataObject/Generator/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @link https://github.com/roojs/PDO_DataObject
*/

#[AllowDynamicProperties]
class PDO_DataObject_Generator_Table {

/**
Expand Down
1 change: 1 addition & 0 deletions PDO/DataObject/Introspection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/


#[AllowDynamicProperties]
abstract class PDO_DataObject_Introspection
{
/**
Expand Down
1 change: 1 addition & 0 deletions PDO/DataObject/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
*
*
*/
#[AllowDynamicProperties]
class PDO_DataObject_Join {

private $do;
Expand Down
3 changes: 2 additions & 1 deletion PDO/DataObject/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
*
* @package DB_DataObject
*/
class PDO_DataObject_Links
#[AllowDynamicProperties]
class PDO_DataObject_Links
{
/**
* @property {DB_DataObject} do DataObject to apply this to.
Expand Down
1 change: 1 addition & 0 deletions PDO/DataObject/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@



#[AllowDynamicProperties]
class PDO_DataObject_Validate
{

Expand Down
6 changes: 5 additions & 1 deletion tests/37-buffered.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ echo "\n\n--------\n";
echo "basic load a big result set\n" ;


PDO_DataObject::factory('Events')->PDO()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$mysqlAttrUseBufferedQuery = defined('Pdo\\Mysql::ATTR_USE_BUFFERED_QUERY')
? constant('Pdo\\Mysql::ATTR_USE_BUFFERED_QUERY')
: PDO::MYSQL_ATTR_USE_BUFFERED_QUERY;

PDO_DataObject::factory('Events')->PDO()->setAttribute($mysqlAttrUseBufferedQuery, false);

$x = PDO_DataObject::factory('Events');
$x->find();
Expand Down
10 changes: 8 additions & 2 deletions tests/includes/PDO_Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ function __construct($dsn,$user,$pass, $options)
function getAttribute($key)
{

// PDO::MYSQL_ATTR_USE_BUFFERED_QUERY is deprecated since PHP 8.5 in favor of
// Pdo\Mysql::ATTR_USE_BUFFERED_QUERY (only available from PHP 8.4 onwards).
$mysqlAttrUseBufferedQuery = defined('Pdo\\Mysql::ATTR_USE_BUFFERED_QUERY')
? constant('Pdo\\Mysql::ATTR_USE_BUFFERED_QUERY')
: PDO::MYSQL_ATTR_USE_BUFFERED_QUERY;

switch($key) {
case PDO::ATTR_DRIVER_NAME:
// it does this alot!!!?
//echo __FUNCTION__ . '==' . json_encode(func_get_args()) . " => " . $this->_dbtype . "\n";
return $this->_dbtype;
break;
case PDO::MYSQL_ATTR_USE_BUFFERED_QUERY:

case $mysqlAttrUseBufferedQuery:
return 1;

default:
Expand Down