summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/adodb-ado.inc.php18
-rw-r--r--drivers/adodb-ado5.inc.php18
-rw-r--r--drivers/adodb-ads.inc.php23
-rw-r--r--drivers/adodb-db2.inc.php21
-rw-r--r--drivers/adodb-fbsql.inc.php26
-rw-r--r--drivers/adodb-firebird.inc.php18
-rw-r--r--drivers/adodb-ibase.inc.php7
-rw-r--r--drivers/adodb-informix72.inc.php11
-rw-r--r--drivers/adodb-ldap.inc.php494
-rw-r--r--drivers/adodb-mssql.inc.php12
-rw-r--r--drivers/adodb-mssqlnative.inc.php49
-rw-r--r--drivers/adodb-mysqli.inc.php248
-rw-r--r--drivers/adodb-netezza.inc.php2
-rw-r--r--drivers/adodb-oci8.inc.php165
-rw-r--r--drivers/adodb-oci8po.inc.php13
-rw-r--r--drivers/adodb-odbc.inc.php11
-rw-r--r--drivers/adodb-odbc_oracle.inc.php29
-rw-r--r--drivers/adodb-odbtp.inc.php13
-rw-r--r--drivers/adodb-oracle.inc.php19
-rw-r--r--drivers/adodb-pdo.inc.php99
-rw-r--r--drivers/adodb-pdo_firebird.inc.php2
-rw-r--r--drivers/adodb-pdo_oci.inc.php30
-rw-r--r--drivers/adodb-postgres64.inc.php335
-rw-r--r--drivers/adodb-sqlite.inc.php21
-rw-r--r--drivers/adodb-sqlite3.inc.php17
-rw-r--r--drivers/adodb-sybase.inc.php16
26 files changed, 868 insertions, 849 deletions
diff --git a/drivers/adodb-ado.inc.php b/drivers/adodb-ado.inc.php
index df95c690..569f0fcb 100644
--- a/drivers/adodb-ado.inc.php
+++ b/drivers/adodb-ado.inc.php
@@ -122,7 +122,7 @@ class ADODB_ado extends ADOConnection {
adSchemaConstraintColumnUsage = 6,
adSchemaConstraintTableUsage = 7,
adSchemaKeyColumnUsage = 8,
- adSchemaReferentialContraints = 9,
+ adSchemaReferentialConstraints = 9,
adSchemaTableConstraints = 10,
adSchemaColumnsDomainUsage = 11,
adSchemaIndexes = 12,
@@ -345,16 +345,6 @@ class ADORecordSet_ado extends ADORecordSet {
var $canSeek = true;
var $hideErrors = true;
- function __construct($id,$mode=false)
- {
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->fetchMode = $mode;
- parent::__construct($id);
- }
-
// returns the field object
function FetchField($fieldOffset = -1) {
@@ -584,7 +574,7 @@ class ADORecordSet_ado extends ADORecordSet {
$val=(float) variant_cast($f->value,VT_R8)*3600*24-2209161600;
else
$val = $f->value;
- $this->fields[] = adodb_date('Y-m-d H:i:s',$val);
+ $this->fields[] = date('Y-m-d H:i:s',$val);
}
break;
case 133:// A date value (yyyymmdd)
@@ -599,8 +589,8 @@ class ADORecordSet_ado extends ADORecordSet {
if (!is_numeric($f->value)) $val = variant_date_to_timestamp($f->value);
else $val = $f->value;
- if (($val % 86400) == 0) $this->fields[] = adodb_date('Y-m-d',$val);
- else $this->fields[] = adodb_date('Y-m-d H:i:s',$val);
+ if (($val % 86400) == 0) $this->fields[] = date('Y-m-d',$val);
+ else $this->fields[] = date('Y-m-d H:i:s',$val);
}
break;
case 1: // null
diff --git a/drivers/adodb-ado5.inc.php b/drivers/adodb-ado5.inc.php
index 04b45abf..4ef1da98 100644
--- a/drivers/adodb-ado5.inc.php
+++ b/drivers/adodb-ado5.inc.php
@@ -147,7 +147,7 @@ class ADODB_ado extends ADOConnection {
adSchemaConstraintColumnUsage = 6,
adSchemaConstraintTableUsage = 7,
adSchemaKeyColumnUsage = 8,
- adSchemaReferentialContraints = 9,
+ adSchemaReferentialConstraints = 9,
adSchemaTableConstraints = 10,
adSchemaColumnsDomainUsage = 11,
adSchemaIndexes = 12,
@@ -382,16 +382,6 @@ class ADORecordSet_ado extends ADORecordSet {
var $canSeek = true;
var $hideErrors = true;
- function __construct($id,$mode=false)
- {
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->fetchMode = $mode;
- parent::__construct($id);
- }
-
// returns the field object
function FetchField($fieldOffset = -1) {
@@ -631,7 +621,7 @@ class ADORecordSet_ado extends ADORecordSet {
$val= (float) variant_cast($f->value,VT_R8)*3600*24-2209161600;
else
$val = $f->value;
- $this->fields[] = adodb_date('Y-m-d H:i:s',$val);
+ $this->fields[] = date('Y-m-d H:i:s',$val);
}
break;
case 133:// A date value (yyyymmdd)
@@ -646,8 +636,8 @@ class ADORecordSet_ado extends ADORecordSet {
if (!is_numeric($f->value)) $val = variant_date_to_timestamp($f->value);
else $val = $f->value;
- if (($val % 86400) == 0) $this->fields[] = adodb_date('Y-m-d',$val);
- else $this->fields[] = adodb_date('Y-m-d H:i:s',$val);
+ if (($val % 86400) == 0) $this->fields[] = date('Y-m-d',$val);
+ else $this->fields[] = date('Y-m-d H:i:s',$val);
}
break;
case 1: // null
diff --git a/drivers/adodb-ads.inc.php b/drivers/adodb-ads.inc.php
index 16eec976..e6cd4f3b 100644
--- a/drivers/adodb-ads.inc.php
+++ b/drivers/adodb-ads.inc.php
@@ -287,7 +287,7 @@ class ADODB_ads extends ADOConnection
// Returns tables,Views or both on successful execution. Returns
// tables by default on successful execution.
- function &MetaTables($ttype = false, $showSchema = false, $mask = false)
+ function MetaTables($ttype = false, $showSchema = false, $mask = false)
{
$recordSet1 = $this->Execute("select * from system.tables");
if (!$recordSet1) {
@@ -325,7 +325,7 @@ class ADODB_ads extends ADOConnection
}
- function &MetaPrimaryKeys($table, $owner = false)
+ function MetaPrimaryKeys($table, $owner = false)
{
$recordSet = $this->Execute("select table_primary_key from system.tables where name='$table'");
if (!$recordSet) {
@@ -533,7 +533,7 @@ class ADODB_ads extends ADOConnection
}
// Returns an array of columns names for a given table
- function &MetaColumnNames($table, $numIndexes = false, $useattnum = false)
+ function MetaColumnNames($table, $numIndexes = false, $useattnum = false)
{
$recordSet = $this->Execute("select name from system.columns where parent='$table'");
if (!$recordSet) {
@@ -684,20 +684,13 @@ class ADORecordSet_ads extends ADORecordSet
var $dataProvider = "ads";
var $useFetchArray;
- function __construct($id, $mode = false)
+ function __construct($queryID, $mode = false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->fetchMode = $mode;
-
- $this->_queryID = $id;
+ parent::__construct($queryID, $mode);
// the following is required for mysql odbc driver in 4.3.1 -- why?
$this->EOF = false;
$this->_currentRow = -1;
- //parent::__construct($id);
}
@@ -760,7 +753,7 @@ class ADORecordSet_ads extends ADORecordSet
function &GetArrayLimit($nrows, $offset = -1)
{
if ($offset <= 0) {
- $rs =& $this->GetArray($nrows);
+ $rs = $this->GetArray($nrows);
return $rs;
}
$savem = $this->fetchMode;
@@ -769,7 +762,7 @@ class ADORecordSet_ads extends ADORecordSet
$this->fetchMode = $savem;
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
- $this->fields =& $this->GetRowAssoc();
+ $this->fields = $this->GetRowAssoc();
}
$results = array();
@@ -802,7 +795,7 @@ class ADORecordSet_ads extends ADORecordSet
$rez = @ads_fetch_into($this->_queryID, $this->fields);
if ($rez) {
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
- $this->fields =& $this->GetRowAssoc();
+ $this->fields = $this->GetRowAssoc();
}
return true;
}
diff --git a/drivers/adodb-db2.inc.php b/drivers/adodb-db2.inc.php
index 60cd093a..d0810fee 100644
--- a/drivers/adodb-db2.inc.php
+++ b/drivers/adodb-db2.inc.php
@@ -11,7 +11,7 @@
* about all the changes, see the update information on the ADOdb website
* for version 5.21.0.
*
- * @link http://pecl.php.net/package/ibm_db2 PECL Extension For DB2
+ * @link https://pecl.php.net/package/ibm_db2 PECL Extension For DB2
*
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
*
@@ -179,7 +179,7 @@ class ADODB_db2 extends ADOConnection {
$db2Options);
}
else
-
+
$this->_connectionID = $db2Function($argDSN,
'',
'',
@@ -193,7 +193,7 @@ class ADODB_db2 extends ADOConnection {
if ($this->_connectionID && $argDatabasename)
$this->execute("SET SCHEMA=$argDatabasename");
-
+
return $this->_connectionID != false;
}
@@ -228,7 +228,7 @@ class ADODB_db2 extends ADOConnection {
$connectionParameters['dsn'] = $argDSN;
$connectionParameters['database'] = $argDatabasename;
$connectionParameters['catalogue'] = false;
-
+
return $connectionParameters;
}
@@ -423,7 +423,7 @@ class ADODB_db2 extends ADOConnection {
{
if (empty($ts) && $ts !== 0) return 'null';
if (is_string($ts)) $ts = ADORecordSet::unixTimeStamp($ts);
- return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'YYYY-MM-DD HH24:MI:SS')";
+ return 'TO_DATE('.date($this->fmtTimeStamp,$ts).",'YYYY-MM-DD HH24:MI:SS')";
}
/**
@@ -1859,17 +1859,6 @@ class ADORecordSet_db2 extends ADORecordSet {
var $dataProvider = "db2";
var $useFetchArray;
- function __construct($id,$mode=false)
- {
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->fetchMode = $mode;
-
- $this->_queryID = $id;
- }
-
// returns the field object
function fetchField($offset = 0)
diff --git a/drivers/adodb-fbsql.inc.php b/drivers/adodb-fbsql.inc.php
index 64913bc2..cfbadf99 100644
--- a/drivers/adodb-fbsql.inc.php
+++ b/drivers/adodb-fbsql.inc.php
@@ -169,20 +169,22 @@ class ADORecordSet_fbsql extends ADORecordSet{
var $databaseType = "fbsql";
var $canSeek = true;
- function __construct($queryID,$mode=false)
+ function __construct($queryID, $mode=false)
{
- if (!$mode) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- switch ($mode) {
- case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break;
- case ADODB_FETCH_ASSOC: $this->fetchMode = FBSQL_ASSOC; break;
- case ADODB_FETCH_BOTH:
- default:
- $this->fetchMode = FBSQL_BOTH; break;
+ parent::__construct($queryID, $mode);
+
+ switch ($this->adodbFetchMode) {
+ case ADODB_FETCH_NUM:
+ $this->fetchMode = FBSQL_NUM;
+ break;
+ case ADODB_FETCH_ASSOC:
+ $this->fetchMode = FBSQL_ASSOC;
+ break;
+ case ADODB_FETCH_BOTH:
+ default:
+ $this->fetchMode = FBSQL_BOTH;
+ break;
}
- parent::__construct($queryID);
}
function _initrs()
diff --git a/drivers/adodb-firebird.inc.php b/drivers/adodb-firebird.inc.php
index db3cca5d..848b3c4e 100644
--- a/drivers/adodb-firebird.inc.php
+++ b/drivers/adodb-firebird.inc.php
@@ -1020,28 +1020,10 @@ class ADORecordset_firebird extends ADORecordSet
private $fieldObjects = false;
/**
- * @var bool Flags if we have retrieved the metadata
- */
- private $fieldObjectsRetrieved = false;
-
- /**
- * @var array Cross-reference the objects by name for easy access
- */
- private $fieldObjectsIndex = array();
-
- /**
* @var bool Flag to indicate if the result has a blob
*/
private $fieldObjectsHaveBlob = false;
- function __construct($id, $mode = false)
- {
- global $ADODB_FETCH_MODE;
-
- $this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode;
- parent::__construct($id);
- }
-
/**
* Returns: an object containing field information.
diff --git a/drivers/adodb-ibase.inc.php b/drivers/adodb-ibase.inc.php
index 8159c512..8d48f17d 100644
--- a/drivers/adodb-ibase.inc.php
+++ b/drivers/adodb-ibase.inc.php
@@ -741,13 +741,6 @@ class ADORecordSet_ibase extends ADORecordSet
var $bind=false;
var $_cacheType;
- function __construct($id,$mode=false)
- {
- global $ADODB_FETCH_MODE;
-
- $this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode;
- parent::__construct($id);
- }
/* Returns: an object containing field information.
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
diff --git a/drivers/adodb-informix72.inc.php b/drivers/adodb-informix72.inc.php
index 6fddde3d..d4083d5e 100644
--- a/drivers/adodb-informix72.inc.php
+++ b/drivers/adodb-informix72.inc.php
@@ -399,17 +399,6 @@ class ADORecordset_informix72 extends ADORecordSet {
var $canSeek = true;
var $_fieldprops = false;
- function __construct($id,$mode=false)
- {
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->fetchMode = $mode;
- parent::__construct($id);
- }
-
-
/* Returns: an object containing field information.
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
diff --git a/drivers/adodb-ldap.inc.php b/drivers/adodb-ldap.inc.php
index e1cba330..91a47c94 100644
--- a/drivers/adodb-ldap.inc.php
+++ b/drivers/adodb-ldap.inc.php
@@ -31,70 +31,101 @@ if (!defined('LDAP_ASSOC')) {
define('LDAP_BOTH',ADODB_FETCH_BOTH);
}
-class ADODB_ldap extends ADOConnection {
- var $databaseType = 'ldap';
- var $dataProvider = 'ldap';
+class ADODB_ldap extends ADOConnection
+{
+ public $databaseType = 'ldap';
+ public $dataProvider = 'ldap';
- # Connection information
- var $username = false;
- var $password = false;
+ /**
+ * @var string[] Caches the version info
+ */
+ protected $version;
- # Used during searches
- var $filter;
- var $dn;
- var $version;
- var $port = 389;
+ /**
+ * @var string Bind error message, eg. "Binding: invalid credentials"
+ */
+ protected $_bind_errmsg = "Binding: %s";
- # Options configuration information
- var $LDAP_CONNECT_OPTIONS;
-
- # error on binding, eg. "Binding: invalid credentials"
- var $_bind_errmsg = "Binding: %s";
+ protected $connectionParameters = array(
+ LDAP_OPT_PROTOCOL_VERSION => 3,
+ LDAP_OPT_REFERRALS => 0
+ );
- // returns true or false
- function _connect( $host, $username, $password, $ldapbase)
+ /**
+ * Connect to an LDAP Server
+ *
+ * @param string|null $ldapServer The LDAP Server to connect to.
+ * @param string|null $username The username to connect as.
+ * @param string|null $password The password to connect with.
+ * @param string|null $ldapbase The Base DN
+ *
+ * @return bool|null True if connected successfully, false if connection failed, or null if the ldap extension
+ * isn't currently loaded.
+ */
+ public function _connect($ldapServer, $username, $password, $ldapbase)
{
global $LDAP_CONNECT_OPTIONS;
- if ( !function_exists( 'ldap_connect' ) ) return null;
+ if (!function_exists('ldap_connect')) {
+ return null;
+ }
- if (strpos($host,'ldap://') === 0 || strpos($host,'ldaps://') === 0) {
- $this->_connectionID = @ldap_connect($host);
- } else {
- $conn_info = array( $host,$this->port);
+ if (strpos($ldapServer, 'ldap://') !== 0 && strpos($ldapServer, 'ldaps://') !== 0) {
+ /*
+ * If ldap SSL not explicitly specified, fall back to insecure
+ */
+ $ldapServer = sprintf('ldap://%s', $ldapServer);
+ }
- if ( strstr( $host, ':' ) ) {
- $conn_info = explode( ':', $host );
- }
+ $this->_connectionID = @ldap_connect($ldapServer);
- $this->_connectionID = @ldap_connect( $conn_info[0], $conn_info[1] );
- }
if (!$this->_connectionID) {
- $e = 'Could not connect to ' . $conn_info[0];
+ $e = 'Could not connect to ' . $ldapServer;
$this->_errorMsg = $e;
- if ($this->debug) ADOConnection::outp($e);
+ if ($this->debug) {
+ ADOConnection::outp($e);
+ }
+
return false;
}
- if(!empty($LDAP_CONNECT_OPTIONS)) {
- $this->_inject_bind_options( $LDAP_CONNECT_OPTIONS );
+
+ if(!empty($LDAP_CONNECT_OPTIONS) && is_array($LDAP_CONNECT_OPTIONS)) {
+ // Convert options to connectionParameters()
+ trigger_error('$LDAP_CONNECT_OPTIONS is deprecated, use setConnectionParameter() instead', E_USER_DEPRECATED);
+ $this->_inject_bind_options($LDAP_CONNECT_OPTIONS);
+ }
+
+ // Iterate over any connection parameters
+ foreach ($this->connectionParameters as $parameter => $value) {
+ if (!ldap_set_option($this->_connectionID, $parameter, $value)) {
+ if ($this->debug) {
+ $message = sprintf('Warning - Setting connection parameter %s to value %s failed', $parameter,
+ $value);
+ ADOConnection::outp($message);
+ $this->_errorMsg = $message;
+ }
+ }
}
if ($username) {
- $bind = @ldap_bind( $this->_connectionID, $username, $password );
+ $bind = @ldap_bind($this->_connectionID, $username, $password);
} else {
- $username = 'anonymous';
- $bind = @ldap_bind( $this->_connectionID );
+ $bind = @ldap_bind($this->_connectionID);
}
if (!$bind) {
- $e = sprintf($this->_bind_errmsg,ldap_error($this->_connectionID));
+ $e = sprintf($this->_bind_errmsg, ldap_error($this->_connectionID));
$this->_errorMsg = $e;
- if ($this->debug) ADOConnection::outp($e);
+ if ($this->debug) {
+ ADOConnection::outp($e);
+ }
return false;
}
+
$this->_errorMsg = '';
$this->database = $ldapbase;
+
return $this->_connectionID;
}
@@ -150,48 +181,95 @@ class ADODB_ldap extends ADOConnection {
);
*/
- function _inject_bind_options( $options ) {
- foreach( $options as $option ) {
- ldap_set_option( $this->_connectionID, $option["OPTION_NAME"], $option["OPTION_VALUE"] )
- or die( "Unable to set server option: " . $option["OPTION_NAME"] );
+ /**
+ * Converts old style global options into connection parameters
+ *
+ * @param array $options
+ * @return void
+ * @deprecated 5.23.0
+ */
+ private function _inject_bind_options($options)
+ {
+ foreach ($options as $option) {
+ $this->connectionParameters[$option["OPTION_NAME"]] = $option["OPTION_VALUE"];
+ //ldap_set_option( $this->_connectionID, $option["OPTION_NAME"], $option["OPTION_VALUE"] );
+ // or die( "Unable to set server option: " . $option["OPTION_NAME"] );
}
}
- function _query($sql,$inputarr=false)
+
+ /**
+ * Execute a query against the AD Database.
+ *
+ * @param string|array $ldapQuery Query to execute.
+ * @param array $inputarr [Ignored] An optional array of parameters.
+ *
+ * @return resource|false
+ * @noinspection PhpParameterNameChangedDuringInheritanceInspection
+ */
+ function _query($ldapQuery, $inputarr = false)
{
- $rs = @ldap_search( $this->_connectionID, $this->database, $sql );
- $this->_errorMsg = ($rs) ? '' : 'Search error on '.$sql.': '.ldap_error($this->_connectionID);
+ $rs = ldap_search($this->_connectionID, $this->database, $ldapQuery);
+
+ $this->_errorMsg = ($rs) ? '' : 'Search error on ' . $ldapQuery . ': ' . ldap_error($this->_connectionID);
+
return $rs;
}
- function ErrorMsg()
- {
- return $this->_errorMsg;
- }
- function ErrorNo()
+ /**
+ * Returns the last error number from previous AD operation.
+ *
+ * @return int The last error number.
+ */
+ function errorNo()
{
return @ldap_errno($this->_connectionID);
}
- /* closes the LDAP connection */
+ /**
+ * closes the LDAP connection
+ *
+ * @return void
+ */
function _close()
{
- @ldap_close( $this->_connectionID );
+ if (is_resource($this->_connectionID)) {
+ @ldap_close($this->_connectionID);
+ }
+
$this->_connectionID = false;
}
- function SelectDB($db) {
- $this->database = $db;
+ /**
+ * Switches the baseDN to a new value. Just like _connect(),
+ * its impossible to determine if the parameter is correct
+ * until you issue a query
+ *
+ * @return bool true
+ * @noinspection PhpParameterNameChangedDuringInheritanceInspection
+ */
+ public function selectDB($baseDN)
+ {
+ $this->database = $baseDN;
return true;
- } // SelectDB
+ }
- function ServerInfo()
+ /**
+ * Get server version info.
+ *
+ * @return string[]|false Array with multiple string elements that define the connection
+ */
+ public function serverInfo()
{
- if( !empty( $this->version ) ) {
+ if (!empty($this->version)) {
return $this->version;
}
+ if (!is_resource($this->_connectionID)) {
+ return false;
+ }
+
$version = array();
/*
Determines how aliases are handled during search.
@@ -204,16 +282,20 @@ class ADODB_ldap extends ADOConnection {
aliases are dereferenced when locating the base object but not during the search.
Default: LDAP_DEREF_NEVER
*/
- ldap_get_option( $this->_connectionID, LDAP_OPT_DEREF, $version['LDAP_OPT_DEREF'] ) ;
- switch ( $version['LDAP_OPT_DEREF'] ) {
+ ldap_get_option($this->_connectionID, LDAP_OPT_DEREF, $version['LDAP_OPT_DEREF']);
+ switch ($version['LDAP_OPT_DEREF']) {
case 0:
$version['LDAP_OPT_DEREF'] = 'LDAP_DEREF_NEVER';
+ break;
case 1:
$version['LDAP_OPT_DEREF'] = 'LDAP_DEREF_SEARCHING';
+ break;
case 2:
$version['LDAP_OPT_DEREF'] = 'LDAP_DEREF_FINDING';
+ break;
case 3:
$version['LDAP_OPT_DEREF'] = 'LDAP_DEREF_ALWAYS';
+ break;
}
/*
@@ -221,8 +303,8 @@ class ADODB_ldap extends ADOConnection {
LDAP_NO_LIMIT (0) means no limit.
Default: LDAP_NO_LIMIT
*/
- ldap_get_option( $this->_connectionID, LDAP_OPT_SIZELIMIT, $version['LDAP_OPT_SIZELIMIT'] );
- if ( $version['LDAP_OPT_SIZELIMIT'] == 0 ) {
+ ldap_get_option($this->_connectionID, LDAP_OPT_SIZELIMIT, $version['LDAP_OPT_SIZELIMIT']);
+ if ($version['LDAP_OPT_SIZELIMIT'] == 0) {
$version['LDAP_OPT_SIZELIMIT'] = 'LDAP_NO_LIMIT';
}
@@ -231,8 +313,8 @@ class ADODB_ldap extends ADOConnection {
LDAP_NO_LIMIT (0) means no limit.
Default: LDAP_NO_LIMIT
*/
- ldap_get_option( $this->_connectionID, LDAP_OPT_TIMELIMIT, $version['LDAP_OPT_TIMELIMIT'] );
- if ( $version['LDAP_OPT_TIMELIMIT'] == 0 ) {
+ ldap_get_option($this->_connectionID, LDAP_OPT_TIMELIMIT, $version['LDAP_OPT_TIMELIMIT']);
+ if ($version['LDAP_OPT_TIMELIMIT'] == 0) {
$version['LDAP_OPT_TIMELIMIT'] = 'LDAP_NO_LIMIT';
}
@@ -242,8 +324,8 @@ class ADODB_ldap extends ADOConnection {
LDAP_OPT_OFF
Default: ON
*/
- ldap_get_option( $this->_connectionID, LDAP_OPT_REFERRALS, $version['LDAP_OPT_REFERRALS'] );
- if ( $version['LDAP_OPT_REFERRALS'] == 0 ) {
+ ldap_get_option($this->_connectionID, LDAP_OPT_REFERRALS, $version['LDAP_OPT_REFERRALS']);
+ if ($version['LDAP_OPT_REFERRALS'] == 0) {
$version['LDAP_OPT_REFERRALS'] = 'LDAP_OPT_OFF';
} else {
$version['LDAP_OPT_REFERRALS'] = 'LDAP_OPT_ON';
@@ -255,8 +337,8 @@ class ADODB_ldap extends ADOConnection {
LDAP_OPT_OFF
Default: OFF
*/
- ldap_get_option( $this->_connectionID, LDAP_OPT_RESTART, $version['LDAP_OPT_RESTART'] );
- if ( $version['LDAP_OPT_RESTART'] == 0 ) {
+ ldap_get_option($this->_connectionID, LDAP_OPT_RESTART, $version['LDAP_OPT_RESTART']);
+ if ($version['LDAP_OPT_RESTART'] == 0) {
$version['LDAP_OPT_RESTART'] = 'LDAP_OPT_OFF';
} else {
$version['LDAP_OPT_RESTART'] = 'LDAP_OPT_ON';
@@ -268,18 +350,18 @@ class ADODB_ldap extends ADOConnection {
LDAP_VERSION3 (3)
Default: LDAP_VERSION2 (2)
*/
- ldap_get_option( $this->_connectionID, LDAP_OPT_PROTOCOL_VERSION, $version['LDAP_OPT_PROTOCOL_VERSION'] );
- if ( $version['LDAP_OPT_PROTOCOL_VERSION'] == 2 ) {
+ ldap_get_option($this->_connectionID, LDAP_OPT_PROTOCOL_VERSION, $version['LDAP_OPT_PROTOCOL_VERSION']);
+ if ($version['LDAP_OPT_PROTOCOL_VERSION'] == 2) {
$version['LDAP_OPT_PROTOCOL_VERSION'] = 'LDAP_VERSION2';
} else {
$version['LDAP_OPT_PROTOCOL_VERSION'] = 'LDAP_VERSION3';
}
/* The host name (or list of hosts) for the primary LDAP server. */
- ldap_get_option( $this->_connectionID, LDAP_OPT_HOST_NAME, $version['LDAP_OPT_HOST_NAME'] );
- ldap_get_option( $this->_connectionID, LDAP_OPT_ERROR_NUMBER, $version['LDAP_OPT_ERROR_NUMBER'] );
- ldap_get_option( $this->_connectionID, LDAP_OPT_ERROR_STRING, $version['LDAP_OPT_ERROR_STRING'] );
- ldap_get_option( $this->_connectionID, LDAP_OPT_MATCHED_DN, $version['LDAP_OPT_MATCHED_DN'] );
+ ldap_get_option($this->_connectionID, LDAP_OPT_HOST_NAME, $version['LDAP_OPT_HOST_NAME']);
+ ldap_get_option($this->_connectionID, LDAP_OPT_ERROR_NUMBER, $version['LDAP_OPT_ERROR_NUMBER']);
+ ldap_get_option($this->_connectionID, LDAP_OPT_ERROR_STRING, $version['LDAP_OPT_ERROR_STRING']);
+ ldap_get_option($this->_connectionID, LDAP_OPT_MATCHED_DN, $version['LDAP_OPT_MATCHED_DN']);
return $this->version = $version;
}
@@ -289,140 +371,206 @@ class ADODB_ldap extends ADOConnection {
Class Name: Recordset
--------------------------------------------------------------------------------------*/
-class ADORecordSet_ldap extends ADORecordSet{
+class ADORecordSet_ldap extends ADORecordSet
+{
+
+ public $databaseType = "ldap";
+ public $canSeek = false;
+
+ protected $_entryID; /* keeps track of the entry resource identifier */
- var $databaseType = "ldap";
- var $canSeek = false;
- var $_entryID; /* keeps track of the entry resource identifier */
+ protected $seekData = array();
- function __construct($queryID,$mode=false)
+ /**
+ * Constructor
+ *
+ * @param resource $queryID
+ * @param boolean $mode
+ */
+ public function __construct($queryID, $mode = false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- switch ($mode)
- {
- case ADODB_FETCH_NUM:
- $this->fetchMode = LDAP_NUM;
- break;
- case ADODB_FETCH_ASSOC:
- $this->fetchMode = LDAP_ASSOC;
- break;
- case ADODB_FETCH_DEFAULT:
- case ADODB_FETCH_BOTH:
- default:
- $this->fetchMode = LDAP_BOTH;
- break;
- }
+ parent::__construct($queryID, $mode);
- parent::__construct($queryID);
+ switch ($this->adodbFetchMode) {
+ case ADODB_FETCH_NUM:
+ $this->fetchMode = LDAP_NUM;
+ break;
+ case ADODB_FETCH_ASSOC:
+ $this->fetchMode = LDAP_ASSOC;
+ break;
+ case ADODB_FETCH_DEFAULT:
+ case ADODB_FETCH_BOTH:
+ default:
+ $this->fetchMode = LDAP_BOTH;
+ break;
+ }
}
- function _initrs()
+ /**
+ * Recordset initialization stub
+ *
+ * @return void
+ */
+ protected function _initrs()
{
- /*
- This could be teaked to respect the $COUNTRECS directive from ADODB
- It's currently being used in the _fetch() function and the
- GetAssoc() function
- */
- $this->_numOfRows = ldap_count_entries( $this->connection->_connectionID, $this->_queryID );
+ // This could be tweaked to respect the $COUNTRECS directive from ADODB
+ // It's currently being used in the _fetch() function and the GetAssoc() function
+ $this->_numOfRows = ldap_count_entries($this->connection->_connectionID, $this->_queryID);
}
- /*
- Return whole recordset as a multi-dimensional associative array
- */
- function GetAssoc($force_array = false, $first2cols = false, $fetchMode = -1)
+
+ /**
+ * Returns raw, database specific information about a field.
+ *
+ * @link https://adodb.org/dokuwiki/doku.php?id=v5:reference:recordset:fetchfield
+ *
+ * @param int $fieldOffset (Optional) The field number to get information for.
+ *
+ * @return ADOFieldObject|bool
+ */
+ public function fetchField($fieldOffset = -1)
{
- $records = $this->_numOfRows;
- $results = array();
- for ( $i=0; $i < $records; $i++ ) {
- foreach ( $this->fields as $k=>$v ) {
- if ( is_array( $v ) ) {
- if ( $v['count'] == 1 ) {
- $results[$i][$k] = $v[0];
- } else {
- array_shift( $v );
- $results[$i][$k] = $v;
- }
- }
- }
+
+ if (!array_key_exists($fieldOffset, $this->seekData)) {
+ return false;
}
- return $results;
+ $o = new ADOFieldObject;
+ $o->name = $this->seekData[$fieldOffset];
+ $o->max_length = 1024;
+ $o->type = 'C';
+
+ return $o;
}
- function GetRowAssoc($upper = ADODB_ASSOC_CASE)
+ /**
+ * Attempt to fetch a result row using the current fetch mode and return whether or not this was successful.
+ *
+ * @return bool True if row was fetched successfully, otherwise false.
+ */
+ public function _fetch()
{
- $results = array();
- foreach ( $this->fields as $k=>$v ) {
- if ( is_array( $v ) ) {
- if ( $v['count'] == 1 ) {
- $results[$k] = $v[0];
- } else {
- array_shift( $v );
- $results[$k] = $v;
- }
- }
+ if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0) {
+ $this->EOF = true;
+ return false;
}
+ $this->EOF = false;
- return $results;
- }
-
- function GetRowNums()
- {
- $results = array();
- foreach ( $this->fields as $k=>$v ) {
- static $i = 0;
- if (is_array( $v )) {
- if ( $v['count'] == 1 ) {
- $results[$i] = $v[0];
- } else {
- array_shift( $v );
- $results[$i] = $v;
- }
- $i++;
- }
+ if ($this->_currentRow == 0) {
+ $this->_entryID = ldap_first_entry($this->connection->_connectionID, $this->_queryID);
+ } else {
+ $this->_entryID = ldap_next_entry($this->connection->_connectionID, $this->_entryID);
}
- return $results;
- }
- function _fetch()
- {
- if ( $this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0 ) {
+ $r = ldap_get_attributes($this->connection->_connectionID, $this->_entryID);
+
+ if (!$r) {
+ $this->EOF = true;
return false;
}
- if ( $this->_currentRow == 0 ) {
- $this->_entryID = ldap_first_entry( $this->connection->_connectionID, $this->_queryID );
- } else {
- $this->_entryID = ldap_next_entry( $this->connection->_connectionID, $this->_entryID );
+ $rowentries = $r['count'];
+ unset($r['count']);
+
+ $objectClass = false;
+
+ if ($r[0] == 'objectClass') {
+ /*
+ * Always an array, move to the end of the row we want to use getAssoc
+ */
+ $objectClass = $r['objectClass'];
+ unset($r[0]);
+ unset($r['objectClass']);
+ unset($objectClass['count']);
}
- $this->fields = ldap_get_attributes( $this->connection->_connectionID, $this->_entryID );
- $this->_numOfFields = $this->fields['count'];
+ $rowData = array();
+ $rowIndex = 0;
+ for ($rowentry = 0; $rowentry < $rowentries; $rowentry++) {
+ if (!array_key_exists($rowentry, $r)) /*
+ * We moved objectClass
+ */ {
+ continue;
+ }
- switch ( $this->fetchMode ) {
+ $eName = $r[$rowentry];
+ $eData = $r[$eName];
+ $dataEntries = $eData['count'];
- case LDAP_ASSOC:
- $this->fields = $this->GetRowAssoc();
- break;
+ unset($eData['count']);
- case LDAP_NUM:
- $this->fields = array_merge($this->GetRowNums(),$this->GetRowAssoc());
- break;
+ if ($dataEntries == 1) {
+ $element = $eData[0];
+ } else {
+ $element = $eData;
+ }
- case LDAP_BOTH:
- default:
- $this->fields = $this->GetRowNums();
+ switch ($this->fetchMode) {
+ case LDAP_ASSOC:
+ $rowData[$eName] = $element;
+ break;
+ case LDAP_NUM:
+ $rowData[$rowIndex] = $element;
+ break;
+ case LDAP_BOTH:
+ default:
+ $rowData[$eName] = $element;
+ $rowData[$rowIndex] = $element;
+ break;
+ }
+
+ $this->seekData[$rowIndex] = $eName;
+
+ $rowIndex++;
+ }
+
+ if ($objectClass) {
+ // Append the element onto the end of the row
+ switch ($this->fetchMode) {
+ case LDAP_ASSOC:
+ $rowData['objectClass'] = $objectClass;
+ break;
+ case LDAP_NUM:
+ $rowData[$rowIndex] = $objectClass;
+ break;
+ case LDAP_BOTH:
+ default:
+ $rowData['objectClass'] = $objectClass;
+ $rowData[$rowIndex] = $objectClass;
+ break;
+ }
+ }
+
+ switch (ADODB_ASSOC_CASE) {
+ case ADODB_ASSOC_CASE_UPPER:
+ $rowData = array_change_key_case($rowData, CASE_UPPER);
+ array_map('strtoupper', $this->seekData);
+ break;
+ case ADODB_ASSOC_CASE_LOWER:
+ $rowData = array_change_key_case($rowData, CASE_LOWER);
+ array_map('strtolower', $this->seekData);
break;
}
- return is_array( $this->fields );
+ $this->bind = array_flip($this->seekData);
+
+ $this->fields = $rowData;
+ $this->_numOfFields = count($rowData);
+
+ return is_array($this->fields);
}
- function _close() {
- @ldap_free_result( $this->_queryID );
+ /**
+ * Frees the memory from a query recordset
+ *
+ * @return void
+ */
+ public function _close()
+ {
+ if (is_resource($this->_queryID)) {
+ @ldap_free_result($this->_queryID);
+ }
+
$this->_queryID = false;
}
diff --git a/drivers/adodb-mssql.inc.php b/drivers/adodb-mssql.inc.php
index c0b714ed..c0a2eabd 100644
--- a/drivers/adodb-mssql.inc.php
+++ b/drivers/adodb-mssql.inc.php
@@ -857,18 +857,12 @@ class ADORecordset_mssql extends ADORecordSet {
var $hasFetchAssoc; // see PHPLens Issue No: 6083
// _mths works only in non-localised system
- function __construct($id,$mode=false)
+ function __construct($queryID, $mode=false)
{
+ parent::__construct($queryID, $mode);
+
// freedts check...
$this->hasFetchAssoc = function_exists('mssql_fetch_assoc');
-
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
-
- }
- $this->fetchMode = $mode;
- return parent::__construct($id);
}
diff --git a/drivers/adodb-mssqlnative.inc.php b/drivers/adodb-mssqlnative.inc.php
index f7e1bcc1..a7640625 100644
--- a/drivers/adodb-mssqlnative.inc.php
+++ b/drivers/adodb-mssqlnative.inc.php
@@ -136,26 +136,12 @@ class ADODB_mssqlnative extends ADOConnection {
$this->mssql_version = $version;
}
- function ServerInfo() {
- global $ADODB_FETCH_MODE;
- static $arr = false;
- if (is_array($arr))
- return $arr;
- if ($this->fetchMode === false) {
- $savem = $ADODB_FETCH_MODE;
- $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
- } elseif ($this->fetchMode >=0 && $this->fetchMode <=2) {
- $savem = $this->fetchMode;
- } else
- $savem = $this->SetFetchMode(ADODB_FETCH_NUM);
-
- $arrServerInfo = sqlsrv_server_info($this->_connectionID);
- $ADODB_FETCH_MODE = $savem;
-
- $arr = array();
- $arr['description'] = $arrServerInfo['SQLServerName'].' connected to '.$arrServerInfo['CurrentDatabase'];
- $arr['version'] = $arrServerInfo['SQLServerVersion'];//ADOConnection::_findvers($arr['description']);
- return $arr;
+ function serverInfo() {
+ $info = sqlsrv_server_info($this->_connectionID);
+ return array(
+ 'description' => $info['SQLServerName'] . ' connected to ' . $info['CurrentDatabase'],
+ 'version' => $info['SQLServerVersion'],
+ );
}
function IfNull( $field, $ifNull )
@@ -1053,15 +1039,6 @@ class ADORecordset_mssqlnative extends ADORecordSet {
var $fieldOffset = 0;
// _mths works only in non-localised system
- /**
- * @var bool True if we have retrieved the fields metadata
- */
- private $fieldObjectsRetrieved = false;
-
- /*
- * Cross-reference the objects by name for easy access
- */
- private $fieldObjectsIndex = array();
/*
* Cross references the dateTime objects for faster decoding
@@ -1107,20 +1084,6 @@ class ADORecordset_mssqlnative extends ADORecordSet {
);
-
-
- function __construct($id,$mode=false)
- {
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
-
- }
- $this->fetchMode = $mode;
- parent::__construct($id);
- }
-
-
function _initrs()
{
$this->_numOfRows = -1;//not supported
diff --git a/drivers/adodb-mysqli.inc.php b/drivers/adodb-mysqli.inc.php
index a6678274..7d5282ed 100644
--- a/drivers/adodb-mysqli.inc.php
+++ b/drivers/adodb-mysqli.inc.php
@@ -22,6 +22,9 @@
*
* @copyright 2000-2013 John Lim
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
+ *
+ * @noinspection PhpComposerExtensionStubsInspection, SqlNoDataSourceInspection
+ * @noinspection PhpMissingFieldTypeInspection, PhpMissingParamTypeInspection, PhpMissingReturnTypeInspection
*/
// security - hide paths
@@ -44,7 +47,8 @@ class ADODB_mysqli extends ADOConnection {
var $dataProvider = 'mysql';
var $hasInsertID = true;
var $hasAffectedRows = true;
- var $metaTablesSQL = "SELECT
+ var $metaTablesSQL = /** @lang text */
+ "SELECT
TABLE_NAME,
CASE WHEN TABLE_TYPE = 'VIEW' THEN 'V' ELSE 'T' END
FROM INFORMATION_SCHEMA.TABLES
@@ -66,7 +70,6 @@ class ADODB_mysqli extends ADOConnection {
var $socket = ''; //Default to empty string to fix HHVM bug
var $_bindInputArray = false;
var $nameQuote = '`'; /// string to use to quote identifiers and names
- var $optionFlags = array(array(MYSQLI_READ_DEFAULT_GROUP,0));
var $arrayClass = 'ADORecordSet_array_mysqli';
var $multiQuery = false;
var $ssl_key = null;
@@ -100,9 +103,13 @@ class ADODB_mysqli extends ADOConnection {
/**
* Tells the insert_id method how to obtain the last value, depending on whether
* we are using a stored procedure or not
+ * @var bool
+ * @noinspection PhpPropertyOnlyWrittenInspection
*/
private $usePreparedStatement = false;
private $useLastInsertStatement = false;
+
+ /** @noinspection PhpPropertyOnlyWrittenInspection */
private $usingBoundVariables = false;
private $statementAffectedRows = -1;
@@ -218,21 +225,21 @@ class ADODB_mysqli extends ADOConnection {
/**
* Connect to a database.
*
- * @todo add: parameter int $port, parameter string $socket
- *
* @param string|null $argHostname (Optional) The host to connect to.
* @param string|null $argUsername (Optional) The username to connect as.
* @param string|null $argPassword (Optional) The password to connect with.
- * @param string|null $argDatabasename (Optional) The name of the database to start in when connected.
+ * @param string|null $argDatabaseName (Optional) The name of the database to start in when connected.
* @param bool $persist (Optional) Whether or not to use a persistent connection.
*
* @return bool|null True if connected successfully, false if connection failed, or null if the mysqli extension
* isn't currently loaded.
+ *@todo add: parameter int $port, parameter string $socket
+ *
*/
function _connect($argHostname = null,
$argUsername = null,
$argPassword = null,
- $argDatabasename = null,
+ $argDatabaseName = null,
$persist = false)
{
if(!extension_loaded("mysqli")) {
@@ -255,15 +262,6 @@ class ADODB_mysqli extends ADOConnection {
}
return false;
}
- /*
- I suggest a simple fix which would enable adodb and mysqli driver to
- read connection options from the standard mysql configuration file
- /etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com>
- */
- $this->optionFlags = array();
- foreach($this->optionFlags as $arr) {
- mysqli_options($this->_connectionID,$arr[0],$arr[1]);
- }
// Now merge in the standard connection parameters setting
foreach ($this->connectionParameters as $options) {
@@ -295,20 +293,18 @@ class ADODB_mysqli extends ADOConnection {
}
}
- #if (!empty($this->port)) $argHostname .= ":".$this->port;
- /** @noinspection PhpCastIsUnnecessaryInspection */
$ok = @mysqli_real_connect($this->_connectionID,
$argHostname,
$argUsername,
$argPassword,
- $argDatabasename,
+ $argDatabaseName,
# PHP7 compat: port must be int. Use default port if cast yields zero
(int)$this->port != 0 ? (int)$this->port : 3306,
$this->socket,
$this->clientFlags);
if ($ok) {
- if ($argDatabasename) return $this->selectDB($argDatabasename);
+ if ($argDatabaseName) return $this->selectDB($argDatabaseName);
return true;
} else {
if ($this->debug) {
@@ -325,14 +321,14 @@ class ADODB_mysqli extends ADOConnection {
* @param string|null $argHostname The host to connect to.
* @param string|null $argUsername The username to connect as.
* @param string|null $argPassword The password to connect with.
- * @param string|null $argDatabasename The name of the database to start in when connected.
+ * @param string|null $argDatabaseName The name of the database to start in when connected.
*
* @return bool|null True if connected successfully, false if connection failed, or null if the mysqli extension
* isn't currently loaded.
*/
- function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
+ function _pconnect($argHostname, $argUsername, $argPassword, $argDatabaseName)
{
- return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, true);
+ return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName, true);
}
/**
@@ -565,7 +561,7 @@ class ADODB_mysqli extends ADOConnection {
}
// Reference on Last_Insert_ID on the recommended way to simulate sequences
- var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
+ var $_genIDSQL = /** @lang text */ "update %s set id=LAST_INSERT_ID(id+1);";
var $_genSeqSQL = "create table if not exists %s (id int not null)";
var $_genSeqCountSQL = "select count(*) from %s";
var $_genSeq2SQL = "insert into %s values (%s)";
@@ -688,7 +684,7 @@ class ADODB_mysqli extends ADOConnection {
// parse index data into array
while ($row = $rs->fetchRow()) {
- if ($primary == FALSE AND $row[2] == 'PRIMARY') {
+ if (!$primary AND $row[2] == 'PRIMARY') {
continue;
}
@@ -831,8 +827,6 @@ class ADODB_mysqli extends ADOConnection {
$fraction = $dayFraction * 24 * 3600;
return $date . ' + INTERVAL ' . $fraction.' SECOND';
-
-// return "from_unixtime(unix_timestamp($date)+$fraction)";
}
/**
@@ -957,7 +951,7 @@ class ADODB_mysqli extends ADOConnection {
$this->setFetchMode($savem);
- $create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"];
+ $create_sql = $a_create_table["Create Table"] ?? $a_create_table["Create View"];
$matches = array();
@@ -982,7 +976,7 @@ class ADODB_mysqli extends ADOConnection {
if ( $associative ) {
$foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
} else {
- $foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}";
+ $foreign_keys[$ref_table][] = $my_field[$j] . '=' . $ref_field[$j];
}
}
}
@@ -1000,9 +994,8 @@ class ADODB_mysqli extends ADOConnection {
*/
function MetaColumns($table, $normalize = true)
{
- $false = false;
if (!$this->metaColumnsSQL)
- return $false;
+ return false;
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
@@ -1016,7 +1009,7 @@ class ADODB_mysqli extends ADOConnection {
$SQL = "SELECT column_name, column_type
FROM information_schema.columns
- WHERE table_schema='{$this->database}'
+ WHERE table_schema='$this->database'
AND table_name='$table'";
$schemaArray = $this->getAssoc($SQL);
@@ -1028,7 +1021,7 @@ class ADODB_mysqli extends ADOConnection {
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if (!is_object($rs))
- return $false;
+ return false;
$retarr = array();
while (!$rs->EOF) {
@@ -1101,7 +1094,6 @@ class ADODB_mysqli extends ADOConnection {
*/
function SelectDB($dbName)
{
-// $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
$this->database = $dbName;
if ($this->_connectionID) {
@@ -1160,21 +1152,11 @@ class ADODB_mysqli extends ADOConnection {
*/
function Prepare($sql)
{
- /*
- * Flag the insert_id method to use the correct retrieval method
- */
+ // Flag the insert_id method to use the correct retrieval method
$this->usePreparedStatement = true;
- /*
- * Prepared statements are not yet handled correctly
- */
+ // Prepared statements are not yet handled correctly
return $sql;
- $stmt = $this->_connectionID->prepare($sql);
- if (!$stmt) {
- echo $this->errorMsg();
- return $sql;
- }
- return array($sql,$stmt);
}
public function execute($sql, $inputarr = false)
@@ -1281,12 +1263,6 @@ class ADODB_mysqli extends ADOConnection {
function _query($sql, $inputarr = false)
{
global $ADODB_COUNTRECS;
- // Move to the next recordset, or return false if there is none. In a stored proc
- // call, mysqli_next_result returns true for the last "recordset", but mysqli_store_result
- // returns false. I think this is because the last "recordset" is actually just the
- // return value of the stored proc (ie the number of rows affected).
- // Commented out for reasons of performance. You should retrieve every recordset yourself.
- // if (!mysqli_next_result($this->connection->_connectionID)) return false;
// When SQL is empty, mysqli_query() throws exception on PHP 8 (#945)
if (!$sql) {
@@ -1296,80 +1272,39 @@ class ADODB_mysqli extends ADOConnection {
return false;
}
- if (is_array($sql)) {
-
- // Prepare() not supported because mysqli_stmt_execute does not return a recordset, but
- // returns as bound variables.
-
- $stmt = $sql[1];
- $a = '';
- foreach($inputarr as $v) {
- if (is_string($v)) $a .= 's';
- else if (is_integer($v)) $a .= 'i';
- else $a .= 'd';
- }
-
- /*
- * set prepared statement flags
- */
- if ($this->usePreparedStatement)
- $this->useLastInsertStatement = true;
-
- $fnarr = array_merge( array($stmt,$a) , $inputarr);
- call_user_func_array('mysqli_stmt_bind_param',$fnarr);
- return mysqli_stmt_execute($stmt);
- }
- else if (is_string($sql) && is_array($inputarr))
- {
-
- /*
- * This is support for true prepared queries
- * with bound parameters
- *
- * set prepared statement flags
- */
+ if (is_string($sql) && is_array($inputarr)) {
+ // This is support for true prepared queries with bound parameters
+ // set prepared statement flags
$this->usePreparedStatement = true;
$this->usingBoundVariables = true;
$bulkBindArray = array();
- if (is_array($inputarr[0]))
- {
+ if (is_array($inputarr[0])) {
$bulkBindArray = $inputarr;
$inputArrayCount = count($inputarr[0]) - 1;
- }
- else
- {
+ } else {
$bulkBindArray[] = $inputarr;
$inputArrayCount = count($inputarr) - 1;
}
-
- /*
- * Prepare the statement with the placeholders,
- * prepare will fail if the statement is invalid
- * so we trap and error if necessary. Note that we
- * are calling MySQL prepare here, not ADOdb
- */
+ // Prepare the statement with the placeholders
+ // prepare will fail if the statement is invalid, so we trap and error if necessary.
+ // Note that we are calling MySQL prepare here, not ADOdb
$stmt = $this->_connectionID->prepare($sql);
- if ($stmt === false)
- {
+ if ($stmt === false) {
$this->outp_throw(
"SQL Statement failed on preparation: " . htmlspecialchars($sql) . "'",
'Execute'
);
return false;
}
- /*
- * Make sure the number of parameters provided in the input
- * array matches what the query expects. We must discount
- * the first parameter which contains the data types in
- * our inbound parameters
- */
- $nparams = $stmt->param_count;
- if ($nparams != $inputArrayCount)
- {
+ // Make sure the number of parameters provided in the input array
+ // matches what the query expects. We must discount the first
+ // parameter which contains the data types in our inbound parameters
+ $nparams = $stmt->param_count;
+ if ($nparams != $inputArrayCount) {
$this->outp_throw(
"Input array has " . $inputArrayCount .
" params, does not match query: '" . htmlspecialchars($sql) . "'",
@@ -1378,37 +1313,28 @@ class ADODB_mysqli extends ADOConnection {
return false;
}
- foreach ($bulkBindArray as $inputarr)
- {
- /*
- * Must pass references into call_user_func_array
- */
+ foreach ($bulkBindArray as $inputarr) {
+ // Must pass references into call_user_func_array
$paramsByReference = array();
- foreach($inputarr as $key => $value) {
+ foreach ($inputarr as $key => $value) {
/** @noinspection PhpArrayAccessCanBeReplacedWithForeachValueInspection */
$paramsByReference[$key] = &$inputarr[$key];
}
- /*
- * Bind the params
- */
+ // Bind the params
call_user_func_array(array($stmt, 'bind_param'), $paramsByReference);
- /*
- * Execute
- */
-
+ // Execute
$ret = mysqli_stmt_execute($stmt);
// Store error code and message
$this->_errorCode = $stmt->errno;
$this->_errorMsg = $stmt->error;
- /*
- * Did we throw an error?
- */
- if ($ret == false)
+ // Did we throw an error?
+ if (!$ret) {
return false;
+ }
}
// Tells affected_rows to be compliant
@@ -1420,14 +1346,9 @@ class ADODB_mysqli extends ADOConnection {
// Turn the statement into a result set and return it
return $stmt->get_result();
- }
- else
- {
- /*
- * reset prepared statement flags, in case we set them
- * previously and didn't use them
- */
- $this->usePreparedStatement = false;
+ } else {
+ // Reset prepared statement flags, in case we set them previously and didn't use them
+ $this->usePreparedStatement = false;
$this->useLastInsertStatement = false;
// Reset error code and message
@@ -1435,19 +1356,12 @@ class ADODB_mysqli extends ADOConnection {
$this->_errorMsg = '';
}
- /*
- if (!$mysql_res = mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) {
- if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->errorMsg());
- return false;
- }
-
- return $mysql_res;
- */
-
if ($this->multiQuery) {
- $rs = mysqli_multi_query($this->_connectionID, $sql.';');
+ $rs = mysqli_multi_query($this->_connectionID, $sql . ';');
if ($rs) {
- $rs = ($ADODB_COUNTRECS) ? @mysqli_store_result( $this->_connectionID ) : @mysqli_use_result( $this->_connectionID );
+ $rs = ($ADODB_COUNTRECS)
+ ? @mysqli_store_result($this->_connectionID)
+ : @mysqli_use_result($this->_connectionID);
return $rs ?: true; // mysqli_more_results( $this->_connectionID )
}
} else {
@@ -1458,11 +1372,10 @@ class ADODB_mysqli extends ADOConnection {
}
}
- if($this->debug)
+ if ($this->debug) {
ADOConnection::outp("Query: " . $sql . " failed. " . $this->errorMsg());
-
+ }
return false;
-
}
/**
@@ -1584,12 +1497,9 @@ class ADORecordSet_mysqli extends ADORecordSet{
function __construct($queryID, $mode = false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
+ parent::__construct($queryID, $mode);
- switch ($mode) {
+ switch ($this->adodbFetchMode) {
case ADODB_FETCH_NUM:
$this->fetchMode = MYSQLI_NUM;
break;
@@ -1602,8 +1512,6 @@ class ADORecordSet_mysqli extends ADORecordSet{
$this->fetchMode = MYSQLI_BOTH;
break;
}
- $this->adodbFetchMode = $mode;
- parent::__construct($queryID);
}
function _initrs()
@@ -1647,7 +1555,7 @@ class ADORecordSet_mysqli extends ADORecordSet{
{
$fieldnr = $fieldOffset;
if ($fieldOffset != -1) {
- $fieldOffset = @mysqli_field_seek($this->_queryID, $fieldnr);
+ @mysqli_field_seek($this->_queryID, $fieldnr);
}
$o = @mysqli_fetch_field($this->_queryID);
if (!$o) return false;
@@ -1860,16 +1768,16 @@ class ADORecordSet_mysqli extends ADORecordSet{
*
* @param string|object $t The type to get the MetaType character for.
* @param int $len (Optional) Redundant. Will always be set to -1.
- * @param bool|object $fieldobj (Optional)
+ * @param bool|object $fieldObj (Optional)
*
* @return string The MetaType
*/
- function metaType($t, $len = -1, $fieldobj = false)
+ function metaType($t, $len = -1, $fieldObj = false)
{
if (is_object($t)) {
- $fieldobj = $t;
- $t = $fieldobj->type;
- $len = $fieldobj->max_length;
+ $fieldObj = $t;
+ $t = $fieldObj->type;
+ $len = $fieldObj->max_length;
}
$t = strtoupper($t);
@@ -1895,7 +1803,8 @@ class ADORecordSet_mysqli extends ADORecordSet{
case MYSQLI_TYPE_STRING :
case MYSQLI_TYPE_ENUM :
case MYSQLI_TYPE_SET :
- case 253 :
+ /** @noinspection PhpMissingBreakStatementInspection */
+ case MYSQLI_TYPE_VAR_STRING :
if ($len <= $this->blobSize) {
return 'C';
}
@@ -1915,7 +1824,7 @@ class ADORecordSet_mysqli extends ADORecordSet{
case MYSQLI_TYPE_BLOB :
case MYSQLI_TYPE_LONG_BLOB :
case MYSQLI_TYPE_MEDIUM_BLOB :
- return !empty($fieldobj->binary) ? 'B' : 'X';
+ return !empty($fieldObj->binary) ? 'B' : 'X';
case 'YEAR':
case 'DATE':
@@ -1945,7 +1854,7 @@ class ADORecordSet_mysqli extends ADORecordSet{
case MYSQLI_TYPE_LONGLONG :
case MYSQLI_TYPE_SHORT :
case MYSQLI_TYPE_TINY :
- if (!empty($fieldobj->primary_key)) {
+ if (!empty($fieldObj->primary_key)) {
return 'R';
}
return 'I';
@@ -1979,16 +1888,16 @@ class ADORecordSet_array_mysqli extends ADORecordSet_array
*
* @param string|object $t The type to get the MetaType character for.
* @param int $len (Optional) Redundant. Will always be set to -1.
- * @param bool|object $fieldobj (Optional)
+ * @param bool|object $fieldObj (Optional)
*
* @return string The MetaType
*/
- function MetaType($t, $len = -1, $fieldobj = false)
+ function MetaType($t, $len = -1, $fieldObj = false)
{
if (is_object($t)) {
- $fieldobj = $t;
- $t = $fieldobj->type;
- $len = $fieldobj->max_length;
+ $fieldObj = $t;
+ $t = $fieldObj->type;
+ $len = $fieldObj->max_length;
}
$t = strtoupper($t);
@@ -2012,7 +1921,8 @@ class ADORecordSet_array_mysqli extends ADORecordSet_array
case MYSQLI_TYPE_STRING :
case MYSQLI_TYPE_ENUM :
case MYSQLI_TYPE_SET :
- case 253 :
+ /** @noinspection PhpMissingBreakStatementInspection */
+ case MYSQLI_TYPE_VAR_STRING :
if ($len <= $this->blobSize) {
return 'C';
}
@@ -2032,7 +1942,7 @@ class ADORecordSet_array_mysqli extends ADORecordSet_array
case MYSQLI_TYPE_BLOB :
case MYSQLI_TYPE_LONG_BLOB :
case MYSQLI_TYPE_MEDIUM_BLOB :
- return !empty($fieldobj->binary) ? 'B' : 'X';
+ return !empty($fieldObj->binary) ? 'B' : 'X';
case 'YEAR':
case 'DATE':
@@ -2062,7 +1972,7 @@ class ADORecordSet_array_mysqli extends ADORecordSet_array
case MYSQLI_TYPE_LONGLONG :
case MYSQLI_TYPE_SHORT :
case MYSQLI_TYPE_TINY :
- if (!empty($fieldobj->primary_key)) {
+ if (!empty($fieldObj->primary_key)) {
return 'R';
}
return 'I';
diff --git a/drivers/adodb-netezza.inc.php b/drivers/adodb-netezza.inc.php
index dc7c58e4..76858909 100644
--- a/drivers/adodb-netezza.inc.php
+++ b/drivers/adodb-netezza.inc.php
@@ -61,7 +61,7 @@ class ADODB_netezza extends ADODB_postgres64 {
var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt.
var $ansiOuter = true;
var $autoRollback = true; // apparently pgsql does not autorollback properly before 4.3.4
- // http://bugs.php.net/bug.php?id=25404
+ // https://bugs.php.net/bug.php?id=25404
function MetaColumns($table,$upper=true)
diff --git a/drivers/adodb-oci8.inc.php b/drivers/adodb-oci8.inc.php
index b92281c7..f08700fd 100644
--- a/drivers/adodb-oci8.inc.php
+++ b/drivers/adodb-oci8.inc.php
@@ -69,13 +69,23 @@ class ADODB_oci8 extends ADOConnection {
var $_stmt;
var $_commit = OCI_COMMIT_ON_SUCCESS;
var $_initdate = true; // init date to YYYY-MM-DD
- var $metaTablesSQL = "select table_name,table_type from cat where table_type in ('TABLE','VIEW') and table_name not like 'BIN\$%'"; // bin$ tables are recycle bin tables
- var $metaColumnsSQL = "select cname,coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net
- var $metaColumnsSQL2 = "select column_name,data_type,data_length, data_scale, data_precision,
- case when nullable = 'Y' then 'NULL'
- else 'NOT NULL' end as nulls,
- data_default from all_tab_cols
- where owner='%s' and table_name='%s' order by column_id"; // when there is a schema
+ var $metaTablesSQL = <<<ENDSQL
+ SELECT table_name, table_type
+ FROM user_catalog
+ WHERE table_type IN ('TABLE', 'VIEW') AND table_name NOT LIKE 'BIN\$%'
+ ENDSQL; // bin$ tables are recycle bin tables
+ var $metaColumnsSQL = <<<ENDSQL
+ SELECT column_name, data_type, data_length, data_scale, data_precision, nullable, data_default
+ FROM user_tab_columns
+ WHERE table_name = '%s'
+ ORDER BY column_id
+ ENDSQL;
+ var $metaColumnsSQL2 = <<<ENDSQL
+ SELECT column_name, data_type, data_length, data_scale, data_precision, nullable, data_default
+ FROM all_tab_columns
+ WHERE owner = '%s' AND table_name = '%s'
+ ORDER BY column_id
+ ENDSQL; // When there is a schema
var $_bindInputArray = true;
var $hasGenID = true;
var $_genIDSQL = "SELECT (%s.nextval) FROM DUAL";
@@ -95,7 +105,7 @@ END;
var $_bind = array();
var $_nestedSQL = true;
var $_getarray = false; // currently not working
- var $leftOuter = ''; // oracle wierdness, $col = $value (+) for LEFT OUTER, $col (+)= $value for RIGHT OUTER
+ var $leftOuter = ''; // oracle weirdness, $col = $value (+) for LEFT OUTER, $col (+)= $value for RIGHT OUTER
var $session_sharing_force_blob = false; // alter session on updateblob if set to true
var $firstrows = true; // enable first rows optimization on SelectLimit()
var $selectOffsetAlg1 = 1000; // when to use 1st algorithm of selectlimit.
@@ -105,8 +115,6 @@ END;
var $datetime = false; // MetaType('DATE') returns 'D' (datetime==false) or 'T' (datetime == true)
var $_refLOBs = array();
- // var $ansiOuter = true; // if oracle9
-
/*
* Legacy compatibility for sequence names for emulated auto-increments
*/
@@ -163,7 +171,7 @@ END;
}
$fld->max_length = $rs->fields[4];
}
- $fld->not_null = (strncmp($rs->fields[5], 'NOT',3) === 0);
+ $fld->not_null = $rs->fields[5] == 'N';
$fld->binary = (strpos($fld->type,'BLOB') !== false);
$fld->default_value = $rs->fields[6];
@@ -193,21 +201,33 @@ END;
}
/**
+ * Connect to database.
+ *
* Multiple modes of connection are supported:
*
- * a. Local Database
- * $conn->Connect(false,'scott','tiger');
+ * 1. Local Database
+ * $conn->connect(false, 'scott', 'tiger');
*
- * b. From tnsnames.ora
- * $conn->Connect($tnsname,'scott','tiger');
- * $conn->Connect(false,'scott','tiger',$tnsname);
+ * 2. From tnsnames.ora
+ * $conn->connect($tnsname, 'scott', 'tiger');
+ * OR
+ * $conn->connect(false, 'scott', 'tiger', $tnsname);
*
- * c. Server + service name
- * $conn->Connect($serveraddress,'scott,'tiger',$service_name);
+ * 3. Server + service name
+ * $conn->connect($serveraddress, 'scott, 'tiger', $service_name);
*
- * d. Server + SID
+ * 4. Server + SID
* $conn->connectSID = true;
* $conn->Connect($serveraddress,'scott,'tiger',$SID);
+ * OR
+ * $conn->Connect($serveraddress,'scott,'tiger',"SID=$SID");
+ *
+ * By default, the Session Mode will be set to OCI_DEFAULT, but it is
+ * possible to use one of other modes referenced in the
+ * {@link https://www.php.net/manual/en/function.oci-connect oci8_connect()}
+ * function's documentation, like this:
+ * $conn->setConnectionParameter('session_mode', OCI_SYSDBA);
+ * $conn->connect(...);
*
* @param string|false $argHostname DB server hostname or TNS name
* @param string $argUsername
@@ -245,45 +265,60 @@ END;
$argDatabasename = substr($argDatabasename,4);
$this->connectSID = true;
}
-
- if ($this->connectSID) {
- $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
- .")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";
- } else
- $argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
- .")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";
+ $sidOrService = $this->connectSID ? 'SID' : 'SERVICE_NAME';
+ $argDatabasename = "(DESCRIPTION="
+ . "(ADDRESS=(PROTOCOL=TCP)(HOST=$argHostname)(PORT=$argHostport))"
+ . "(CONNECT_DATA=($sidOrService=$argDatabasename)))";
}
}
- //if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
- if ($mode==1) {
- $this->_connectionID = ($this->charSet)
- ? oci_pconnect($argUsername,$argPassword, $argDatabasename,$this->charSet)
- : oci_pconnect($argUsername,$argPassword, $argDatabasename);
- if ($this->_connectionID && $this->autoRollback) {
- oci_rollback($this->_connectionID);
+ // Determine the connect function to use based on connection mode
+ switch ($mode) {
+ case 1: $ociConnectFunction = 'oci_pconnect'; break;
+ case 2: $ociConnectFunction = 'oci_new_connect'; break;
+ default: $ociConnectFunction = 'oci_connect';
+ }
+
+ // Process the connection parameters
+ $sessionMode = OCI_DEFAULT;
+ $clientIdentifier = '';
+ foreach ($this->connectionParameters as $options) {
+ foreach($options as $parameter => $value) {
+ switch ($parameter) {
+ case 'session_mode':
+ $sessionMode = $value;
+ break;
+ case 'client_identifier':
+ $clientIdentifier = $value;
+ break;
+ }
}
- } else if ($mode==2) {
- $this->_connectionID = ($this->charSet)
- ? oci_new_connect($argUsername,$argPassword, $argDatabasename,$this->charSet)
- : oci_new_connect($argUsername,$argPassword, $argDatabasename);
- } else {
- $this->_connectionID = ($this->charSet)
- ? oci_connect($argUsername,$argPassword, $argDatabasename,$this->charSet)
- : oci_connect($argUsername,$argPassword, $argDatabasename);
}
+
+ $this->_connectionID = $ociConnectFunction(
+ $argUsername,
+ $argPassword,
+ $argDatabasename,
+ $this->charSet ?: '',
+ $sessionMode
+ );
if (!$this->_connectionID) {
return false;
}
+ // Set client identifier, but see documentation for limitations
+ if ($clientIdentifier) {
+ oci_set_client_identifier($this->_connectionID, $clientIdentifier);
+ }
+
+ if ($mode == 1 && $this->autoRollback ) {
+ oci_rollback($this->_connectionID);
+ }
+
if ($this->_initdate) {
$this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='".$this->NLS_DATE_FORMAT."'");
}
- // looks like:
- // Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production With the Partitioning option JServer Release 8.1.7.0.0 - Production
- // $vers = oci_server_version($this->_connectionID);
- // if (strpos($vers,'8i') !== false) $this->ansiOuter = true;
return true;
}
@@ -371,7 +406,7 @@ END;
$ds = $d->format($this->fmtDate);
}
else {
- $ds = adodb_date($this->fmtDate,$d);
+ $ds = date($this->fmtDate,$d);
}
return "TO_DATE(".$ds.",'".$this->dateformat."')";
@@ -400,7 +435,7 @@ END;
$tss = $ts->format("'Y-m-d H:i:s'");
}
else {
- $tss = adodb_date("'Y-m-d H:i:s'",$ts);
+ $tss = date("'Y-m-d H:i:s'",$ts);
}
return $tss;
@@ -547,7 +582,7 @@ END;
$ok = true;
}
- return $ok ? true : false;
+ return (bool)$ok;
}
function CommitTrans($ok=true)
@@ -1252,9 +1287,9 @@ END;
* $db->Parameter($stmt,$group,'group');
* $db->Execute($stmt);
*
- * @param $stmt Statement returned by {@see Prepare()} or {@see PrepareSP()}.
- * @param $var PHP variable to bind to
- * @param $name Name of stored procedure variable name to bind to.
+ * @param array $stmt Statement returned by {@see Prepare()} or {@see PrepareSP()}.
+ * @param mixed $var PHP variable to bind to
+ * @param string $name Name of stored procedure variable name to bind to.
* @param bool $isOutput Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8.
* @param int $maxLen Holds an maximum length of the variable.
* @param mixed $type The data type of $var. Legal values depend on driver.
@@ -1398,15 +1433,13 @@ END;
$ok = oci_execute($cursor);
return $cursor;
}
- return $stmt;
} else {
if (is_resource($stmt)) {
oci_free_statement($stmt);
return true;
}
- return $stmt;
}
- break;
+ return $stmt;
default :
return true;
@@ -1571,8 +1604,6 @@ SELECT /*+ RULE */ distinct b.column_name
* It remains for backwards compatibility.
*
* @return string Quoted string to be sent back to database
- *
- * @noinspection PhpUnusedParameterInspection
*/
function qStr($s, $magic_quotes=false)
{
@@ -1600,13 +1631,11 @@ class ADORecordset_oci8 extends ADORecordSet {
/** @var resource Cursor reference */
var $_refcursor;
- function __construct($queryID,$mode=false)
+ function __construct($queryID, $mode=false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- switch ($mode) {
+ parent::__construct($queryID, $mode);
+
+ switch ($this->adodbFetchMode) {
case ADODB_FETCH_ASSOC:
$this->fetchMode = OCI_ASSOC;
break;
@@ -1620,8 +1649,6 @@ class ADORecordset_oci8 extends ADORecordSet {
break;
}
$this->fetchMode += OCI_RETURN_NULLS + OCI_RETURN_LOBS;
- $this->adodbFetchMode = $mode;
- $this->_queryID = $queryID;
}
/**
@@ -1821,7 +1848,7 @@ class ADORecordset_oci8 extends ADORecordSet {
* @param mixed $t
* @param int $len [optional] Length of blobsize
* @param bool $fieldobj [optional][discarded]
- * @return str The metatype of the field
+ * @return string The metatype of the field
*/
function MetaType($t, $len=-1, $fieldobj=false)
{
@@ -1876,11 +1903,3 @@ class ADORecordset_oci8 extends ADORecordSet {
}
}
}
-
-class ADORecordSet_ext_oci8 extends ADORecordSet_oci8 {
-
- function MoveNext()
- {
- return adodb_movenext($this);
- }
-}
diff --git a/drivers/adodb-oci8po.inc.php b/drivers/adodb-oci8po.inc.php
index 71c203b6..3ecebebc 100644
--- a/drivers/adodb-oci8po.inc.php
+++ b/drivers/adodb-oci8po.inc.php
@@ -32,8 +32,17 @@ include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
class ADODB_oci8po extends ADODB_oci8 {
var $databaseType = 'oci8po';
var $dataProvider = 'oci8';
- var $metaColumnsSQL = "select lower(cname),coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno"; //changed by smondino@users.sourceforge. net
- var $metaTablesSQL = "select lower(table_name),table_type from cat where table_type in ('TABLE','VIEW')";
+ var $metaTablesSQL = <<<ENDSQL
+ SELECT lower(table_name), table_type
+ FROM user_catalog
+ WHERE table_type IN ('TABLE', 'VIEW') AND table_name NOT LIKE 'BIN\$%'
+ ENDSQL; // bin$ tables are recycle bin tables
+ var $metaColumnsSQL = <<<ENDSQL
+ SELECT lower(column_name), data_type, data_length, data_scale, data_precision, nullable, data_default
+ FROM user_tab_columns
+ WHERE table_name = '%s'
+ ORDER BY column_id
+ ENDSQL;
function Param($name,$type='C')
{
diff --git a/drivers/adodb-odbc.inc.php b/drivers/adodb-odbc.inc.php
index 56db8b0e..59909646 100644
--- a/drivers/adodb-odbc.inc.php
+++ b/drivers/adodb-odbc.inc.php
@@ -613,20 +613,13 @@ class ADORecordSet_odbc extends ADORecordSet {
var $dataProvider = "odbc";
var $useFetchArray;
- function __construct($id,$mode=false)
+ function __construct($queryID, $mode=false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->fetchMode = $mode;
-
- $this->_queryID = $id;
+ parent::__construct($queryID, $mode);
// the following is required for mysql odbc driver in 4.3.1 -- why?
$this->EOF = false;
$this->_currentRow = -1;
- //parent::__construct($id);
}
diff --git a/drivers/adodb-odbc_oracle.inc.php b/drivers/adodb-odbc_oracle.inc.php
index d8461e1a..8c608295 100644
--- a/drivers/adodb-odbc_oracle.inc.php
+++ b/drivers/adodb-odbc_oracle.inc.php
@@ -33,8 +33,17 @@ class ADODB_odbc_oracle extends ADODB_odbc {
var $concat_operator='||';
var $fmtDate = "'Y-m-d 00:00:00'";
var $fmtTimeStamp = "'Y-m-d h:i:sA'";
- var $metaTablesSQL = 'select table_name from cat';
- var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno";
+ var $metaTablesSQL = <<<ENDSQL
+ SELECT table_name, table_type
+ FROM user_catalog
+ WHERE table_type IN ('TABLE', 'VIEW') AND table_name NOT LIKE 'BIN\$%'
+ ENDSQL; // bin$ tables are recycle bin tables
+ var $metaColumnsSQL = <<<ENDSQL
+ SELECT column_name, data_type, data_length, data_scale, data_precision, nullable, data_default
+ FROM user_tab_columns
+ WHERE table_name = '%s'
+ ORDER BY column_id
+ ENDSQL;
var $sysDate = "TRUNC(SYSDATE)";
var $sysTimeStamp = 'SYSDATE';
@@ -42,9 +51,8 @@ class ADODB_odbc_oracle extends ADODB_odbc {
function MetaTables($ttype = false, $showSchema = false, $mask = false)
{
- $false = false;
$rs = $this->Execute($this->metaTablesSQL);
- if ($rs === false) return $false;
+ if ($rs === false) return false;
$arr = $rs->GetArray();
$arr2 = array();
for ($i=0; $i < sizeof($arr); $i++) {
@@ -60,19 +68,20 @@ class ADODB_odbc_oracle extends ADODB_odbc {
$rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table)));
if ($rs === false) {
- $false = false;
- return $false;
+ return false;
}
$retarr = array();
- while (!$rs->EOF) { //print_r($rs->fields);
+ while (!$rs->EOF) {
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$fld->type = $rs->fields[1];
$fld->max_length = $rs->fields[2];
-
- if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
- else $retarr[strtoupper($fld->name)] = $fld;
+ if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) {
+ $retarr[] = $fld;
+ } else {
+ $retarr[strtoupper($fld->name)] = $fld;
+ }
$rs->MoveNext();
}
diff --git a/drivers/adodb-odbtp.inc.php b/drivers/adodb-odbtp.inc.php
index e3f81481..46bf9c4a 100644
--- a/drivers/adodb-odbtp.inc.php
+++ b/drivers/adodb-odbtp.inc.php
@@ -81,7 +81,7 @@ class ADODB_odbtp extends ADOConnection{
if ($isfld) return "convert(date, $d, 120)";
if (is_string($d)) $d = ADORecordSet::UnixDate($d);
- $d = adodb_date($this->fmtDate,$d);
+ $d = date($this->fmtDate,$d);
return "convert(date, $d, 120)";
}
@@ -91,7 +91,7 @@ class ADODB_odbtp extends ADOConnection{
if ($isfld) return "convert(datetime, $d, 120)";
if (is_string($d)) $d = ADORecordSet::UnixDate($d);
- $d = adodb_date($this->fmtDate,$d);
+ $d = date($this->fmtDate,$d);
return "convert(datetime, $d, 120)";
}
*/
@@ -684,15 +684,6 @@ class ADORecordSet_odbtp extends ADORecordSet {
var $databaseType = 'odbtp';
var $canSeek = true;
- function __construct($queryID,$mode=false)
- {
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->fetchMode = $mode;
- parent::__construct($queryID);
- }
function _initrs()
{
diff --git a/drivers/adodb-oracle.inc.php b/drivers/adodb-oracle.inc.php
index dc0462fe..7c061b07 100644
--- a/drivers/adodb-oracle.inc.php
+++ b/drivers/adodb-oracle.inc.php
@@ -41,7 +41,7 @@ class ADODB_oracle extends ADOConnection {
{
if (is_string($d)) $d = ADORecordSet::UnixDate($d);
if (is_object($d)) $ds = $d->format($this->fmtDate);
- else $ds = adodb_date($this->fmtDate,$d);
+ else $ds = date($this->fmtDate,$d);
return 'TO_DATE('.$ds.",'YYYY-MM-DD')";
}
@@ -51,7 +51,7 @@ class ADODB_oracle extends ADOConnection {
if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);
if (is_object($ts)) $ds = $ts->format($this->fmtDate);
- else $ds = adodb_date($this->fmtTimeStamp,$ts);
+ else $ds = date($this->fmtTimeStamp,$ts);
return 'TO_DATE('.$ds.",'RRRR-MM-DD, HH:MI:SS AM')";
}
@@ -223,16 +223,9 @@ class ADORecordset_oracle extends ADORecordSet {
var $databaseType = "oracle";
var $bind = false;
- function __construct($queryID,$mode=false)
+ function __construct($queryID, $mode=false)
{
-
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->fetchMode = $mode;
-
- $this->_queryID = $queryID;
+ parent::__construct($queryID, $mode);
$this->_inited = true;
$this->fields = array();
@@ -249,9 +242,7 @@ class ADORecordset_oracle extends ADORecordSet {
return $this->_queryID;
}
-
-
- /* Returns: an object containing field information.
+ /* Returns: an object containing field information.
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
fetchField() is retrieved. */
diff --git a/drivers/adodb-pdo.inc.php b/drivers/adodb-pdo.inc.php
index d3ce12d0..7fbc8efa 100644
--- a/drivers/adodb-pdo.inc.php
+++ b/drivers/adodb-pdo.inc.php
@@ -66,6 +66,10 @@ function adodb_pdo_type($t)
class ADODB_pdo extends ADOConnection {
+ const BIND_USE_QUESTION_MARKS = 0;
+ const BIND_USE_NAMED_PARAMETERS = 1;
+ const BIND_USE_BOTH = 2;
+
var $databaseType = "pdo";
var $dataProvider = "pdo";
var $fmtDate = "'Y-m-d'";
@@ -100,6 +104,15 @@ class ADODB_pdo extends ADOConnection {
*/
public $pdoParameters = array();
+ /*
+ * Set which style is used to bind parameters
+ *
+ * BIND_USE_QUESTION_MARKS = Use only question marks
+ * BIND_USE_NAMED_PARAMETERS = Use only named parameters
+ * BIND_USE_BOTH = Use both question marks and named parameters (Default)
+ */
+ public $bindParameterStyle = self::BIND_USE_BOTH;
+
function _UpdatePDO()
{
$d = $this->_driver;
@@ -592,11 +605,7 @@ class ADODB_pdo extends ADOConnection {
$this->_driver->debug = $this->debug;
}
if ($inputarr) {
-
- /*
- * inputarr must be numeric
- */
- $inputarr = array_values($inputarr);
+ $inputarr = $this->conformToBindParameterStyle($stmt->queryString, $inputarr);
$ok = $stmt->execute($inputarr);
}
else {
@@ -666,6 +675,58 @@ class ADODB_pdo extends ADOConnection {
return "'" . str_replace("'", $this->replaceQuote, $s) . "'";
}
+ /**
+ * Make bind parameters conform to settings.
+ *
+ * @param string $sql
+ * @param array $inputarr
+ * @return array
+ */
+ private function conformToBindParameterStyle($sql, $inputarr)
+ {
+ switch ($this->bindParameterStyle)
+ {
+ case self::BIND_USE_QUESTION_MARKS:
+ default:
+ $inputarr = array_values($inputarr);
+ break;
+
+ case self::BIND_USE_NAMED_PARAMETERS:
+ break;
+
+ case self::BIND_USE_BOTH:
+ // inputarr must be numeric if SQL contains a question mark
+ if ($this->containsQuestionMarkPlaceholder($sql)) {
+ $inputarr = array_values($inputarr);
+
+ if ($this->debug) {
+ ADOconnection::outp('improve the performance of this query by setting the bindParameterStyle to BIND_USE_QUESTION_MARKS');
+ }
+ }
+ break;
+ }
+
+ return $inputarr;
+ }
+
+ /**
+ * Checks for the inclusion of a question mark placeholder.
+ *
+ * @param string $sql SQL string
+ * @return boolean Returns true if a question mark placeholder is included
+ */
+ private function containsQuestionMarkPlaceholder($sql)
+ {
+ $pattern = '/(.\?(:?.|$))/';
+ if (preg_match_all($pattern, $sql, $matches, PREG_SET_ORDER)) {
+ foreach ($matches as $match) {
+ if ($match[1] !== '`?`' && strpos($match[1], '??') === false) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
/**
@@ -792,27 +853,25 @@ class ADORecordSet_pdo extends ADORecordSet {
/** @var PDOStatement */
var $_queryID;
- function __construct($id,$mode=false)
+ function __construct($queryID, $mode=false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- $this->adodbFetchMode = $mode;
- switch($mode) {
- case ADODB_FETCH_NUM: $mode = PDO::FETCH_NUM; break;
- case ADODB_FETCH_ASSOC: $mode = PDO::FETCH_ASSOC; break;
+ parent::__construct($queryID, $mode);
- case ADODB_FETCH_BOTH:
- default: $mode = PDO::FETCH_BOTH; break;
+ switch($this->adodbFetchMode) {
+ case ADODB_FETCH_NUM:
+ $mode = PDO::FETCH_NUM;
+ break;
+ case ADODB_FETCH_ASSOC:
+ $mode = PDO::FETCH_ASSOC;
+ break;
+ case ADODB_FETCH_BOTH:
+ default:
+ $mode = PDO::FETCH_BOTH;
+ break;
}
$this->fetchMode = $mode;
-
- $this->_queryID = $id;
- parent::__construct($id);
}
-
function Init()
{
if ($this->_inited) {
diff --git a/drivers/adodb-pdo_firebird.inc.php b/drivers/adodb-pdo_firebird.inc.php
index f8847c3c..922407c5 100644
--- a/drivers/adodb-pdo_firebird.inc.php
+++ b/drivers/adodb-pdo_firebird.inc.php
@@ -33,7 +33,7 @@ class ADODB_pdo_firebird extends ADODB_pdo
var $arrayClass = 'ADORecordSet_array_pdo_firebird';
/**
- * Gets the version iformation from the server
+ * Gets the version information from the server
*
* @return string[]
*/
diff --git a/drivers/adodb-pdo_oci.inc.php b/drivers/adodb-pdo_oci.inc.php
index 20b47def..8603e393 100644
--- a/drivers/adodb-pdo_oci.inc.php
+++ b/drivers/adodb-pdo_oci.inc.php
@@ -26,8 +26,17 @@ class ADODB_pdo_oci extends ADODB_pdo_base {
var $sysTimeStamp = 'SYSDATE';
var $NLS_DATE_FORMAT = 'YYYY-MM-DD'; // To include time, use 'RRRR-MM-DD HH24:MI:SS'
var $random = "abs(mod(DBMS_RANDOM.RANDOM,10000001)/10000000)";
- var $metaTablesSQL = "select table_name,table_type from cat where table_type in ('TABLE','VIEW')";
- var $metaColumnsSQL = "select cname,coltype,width, SCALE, PRECISION, NULLS, DEFAULTVAL from col where tname='%s' order by colno";
+ var $metaTablesSQL = <<<ENDSQL
+ SELECT table_name, table_type
+ FROM user_catalog
+ WHERE table_type IN ('TABLE', 'VIEW') AND table_name NOT LIKE 'BIN\$%'
+ ENDSQL; // bin$ tables are recycle bin tables
+ var $metaColumnsSQL = <<<ENDSQL
+ SELECT column_name, data_type, data_length, data_scale, data_precision, nullable, data_default
+ FROM user_tab_columns
+ WHERE table_name = '%s'
+ ORDER BY column_id
+ ENDSQL;
var $_initdate = true;
var $_hasdual = true;
@@ -58,9 +67,8 @@ class ADODB_pdo_oci extends ADODB_pdo_base {
function MetaColumns($table,$normalize=true)
{
- global $ADODB_FETCH_MODE;
+ global $ADODB_FETCH_MODE;
- $false = false;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
@@ -70,20 +78,22 @@ class ADODB_pdo_oci extends ADODB_pdo_base {
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if (!$rs) {
- return $false;
+ return false;
}
$retarr = array();
- while (!$rs->EOF) { //print_r($rs->fields);
+ while (!$rs->EOF) {
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$fld->type = $rs->fields[1];
$fld->max_length = $rs->fields[2];
$fld->scale = $rs->fields[3];
- if ($rs->fields[1] == 'NUMBER' && $rs->fields[3] == 0) {
- $fld->type ='INT';
+ if ($rs->fields[1] == 'NUMBER') {
+ if ($rs->fields[3] == 0) {
+ $fld->type = 'INT';
+ }
$fld->max_length = $rs->fields[4];
}
- $fld->not_null = (strncmp($rs->fields[5], 'NOT',3) === 0);
+ $fld->not_null = $rs->fields[5] == 'N';
$fld->binary = (strpos($fld->type,'BLOB') !== false);
$fld->default_value = $rs->fields[6];
@@ -93,7 +103,7 @@ class ADODB_pdo_oci extends ADODB_pdo_base {
}
$rs->Close();
if (empty($retarr))
- return $false;
+ return false;
else
return $retarr;
}
diff --git a/drivers/adodb-postgres64.inc.php b/drivers/adodb-postgres64.inc.php
index b1d161d7..73f31995 100644
--- a/drivers/adodb-postgres64.inc.php
+++ b/drivers/adodb-postgres64.inc.php
@@ -26,6 +26,10 @@ class ADODB_postgres64 extends ADOConnection{
var $databaseType = 'postgres64';
var $dataProvider = 'postgres';
var $hasInsertID = true;
+ /** @var PgSql\Connection|resource|false Identifier for the native database connection */
+ var $_connectionID = false;
+ /** @var PgSql\Connection|resource|false */
+ var $_queryID;
/** @var PgSql\Connection|resource|false */
var $_resultid = false;
var $concat_operator='||';
@@ -78,21 +82,21 @@ class ADODB_postgres64 extends ADOConnection{
// http://bugs.php.net/bug.php?id=25404
var $uniqueIisR = true;
- var $_bindInputArray = false; // requires postgresql 7.3+ and ability to modify database
+ var $_bindInputArray = false; // requires PostgreSQL 7.3+ and ability to modify database
var $disableBlobs = false; // set to true to disable blob checking, resulting in 2-5% improvement in performance.
/** @var int $_pnum Number of the last assigned query parameter {@see param()} */
var $_pnum = 0;
var $version;
- var $_nestedSQL = false;
+ var $_nestedSQL = true;
// The last (fmtTimeStamp is not entirely correct:
// PostgreSQL also has support for time zones,
// and writes these time in this format: "2001-03-01 18:59:26+02".
// There is no code for the "+02" time zone information, so I just left that out.
// I'm not familiar enough with both ADODB as well as Postgres
- // to know what the concequences are. The other values are correct (wheren't in 0.94)
+ // to know what the consequences are. The other values are correct (weren't in 0.94)
// -- Freek Dijkstra
/**
@@ -135,7 +139,15 @@ class ADODB_postgres64 extends ADOConnection{
return " coalesce($field, $ifNull) ";
}
- // get the last id - never tested
+ /**
+ * Get the last id - never tested.
+ *
+ * @param string $tablename
+ * @param string $fieldname
+ * @return false|mixed
+ *
+ * @noinspection PhpUnused
+ */
function pg_insert_id($tablename,$fieldname)
{
$result=pg_query($this->_connectionID, 'SELECT last_value FROM '. $tablename .'_'. $fieldname .'_seq');
@@ -157,7 +169,9 @@ class ADODB_postgres64 extends ADOConnection{
*/
protected function _insertID($table = '', $column = '')
{
- if ($this->_resultid === false) return false;
+ if ($this->_resultid === false) {
+ return false;
+ }
$oid = pg_last_oid($this->_resultid);
// to really return the id, we need the table and column-name, else we can only return the oid != id
return empty($table) || empty($column) ? $oid : $this->GetOne("SELECT $column FROM $table WHERE oid=".(int)$oid);
@@ -165,7 +179,9 @@ class ADODB_postgres64 extends ADOConnection{
function _affectedrows()
{
- if ($this->_resultid === false) return false;
+ if ($this->_resultid === false) {
+ return false;
+ }
return pg_affected_rows($this->_resultid);
}
@@ -180,13 +196,14 @@ class ADODB_postgres64 extends ADOConnection{
return pg_query($this->_connectionID, 'begin '.$this->_transmode);
}
- function RowLock($tables,$where,$col='1 as adodbignore')
+ function RowLock($table, $where, $col='1 as adodbignore')
{
- if (!$this->transCnt) $this->BeginTrans();
- return $this->GetOne("select $col from $tables where $where for update");
+ if (!$this->transCnt) {
+ $this->BeginTrans();
+ }
+ return $this->GetOne("select $col from $table where $where for update");
}
- // returns true/false.
function CommitTrans($ok=true)
{
if ($this->transOff) return true;
@@ -196,7 +213,6 @@ class ADODB_postgres64 extends ADOConnection{
return pg_query($this->_connectionID, 'commit');
}
- // returns true/false
function RollbackTrans()
{
if ($this->transOff) return true;
@@ -263,8 +279,6 @@ class ADODB_postgres64 extends ADOConnection{
}
}
-
- // Format date column in sql string given an input format that understands Y M D
function SQLDate($fmt, $col=false)
{
if (!$col) $col = $this->sysTimeStamp;
@@ -344,15 +358,24 @@ class ADODB_postgres64 extends ADOConnection{
- /*
- * Load a Large Object from a file
- * - the procedure stores the object id in the table and imports the object using
- * postgres proprietary blob handling routines
- *
- * contributed by Mattia Rossi mattia@technologist.com
- * modified for safe mode by juraj chlebec
- */
- function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB')
+ /**
+ * Update a BLOB from a file.
+ *
+ * The procedure stores the object id in the table and imports the object using
+ * postgres proprietary blob handling routines.
+ *
+ * Usage example:
+ * $conn->updateBlobFile('table', 'blob_col', '/path/to/file', 'id=1');
+ *
+ * @param string $table
+ * @param string $column
+ * @param string $path Filename containing blob data
+ * @param mixed $where {@see updateBlob()}
+ * @param string $blobtype supports 'BLOB' and 'CLOB'
+ *
+ * @return bool success
+ */
+ function updateBlobFile($table,$column,$path,$where,$blobtype='BLOB')
{
pg_query($this->_connectionID, 'begin');
@@ -368,24 +391,25 @@ class ADODB_postgres64 extends ADOConnection{
// $oid = pg_lo_import ($path);
pg_query($this->_connectionID, 'commit');
$rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype);
- $rez = !empty($rs);
- return $rez;
+ return !empty($rs);
}
- /*
- * Deletes/Unlinks a Blob from the database, otherwise it
- * will be left behind
- *
- * Returns TRUE on success or FALSE on failure.
- *
- * contributed by Todd Rogers todd#windfox.net
- */
- function BlobDelete( $blob )
+ /**
+ * Deletes/Unlinks a Blob from the database, otherwise it will be left behind.
+ *
+ * contributed by Todd Rogers todd#windfox.net
+ *
+ * @param mixed $blob
+ * @return bool True on success, false on failure.
+ *
+ * @noinspection PhpUnused
+ */
+ function BlobDelete($blob)
{
pg_query($this->_connectionID, 'begin');
$result = @pg_lo_unlink($this->_connectionID, $blob);
pg_query($this->_connectionID, 'commit');
- return( $result );
+ return $result;
}
/*
@@ -397,19 +421,21 @@ class ADODB_postgres64 extends ADOConnection{
return is_numeric($oid);
}
- /*
- * If an OID is detected, then we use pg_lo_* to open the oid file and read the
- * real blob from the db using the oid supplied as a parameter. If you are storing
- * blobs using bytea, we autodetect and process it so this function is not needed.
- *
- * contributed by Mattia Rossi mattia@technologist.com
- *
- * see http://www.postgresql.org/idocs/index.php?largeobjects.html
- *
- * Since adodb 4.54, this returns the blob, instead of sending it to stdout. Also
- * added maxsize parameter, which defaults to $db->maxblobsize if not defined.
- */
- function BlobDecode($blob,$maxsize=false,$hastrans=true)
+ /**
+ * If an OID is detected, then we use pg_lo_* to open the oid file and read the
+ * real blob from the db using the oid supplied as a parameter. If you are storing
+ * blobs using bytea, we autodetect and process it so this function is not needed.
+ *
+ * Contributed by Mattia Rossi mattia@technologist.com
+ *
+ * @link https://www.postgresql.org/docs/current/largeobjects.html
+ *
+ * @param mixed $blob
+ * @param int|false $maxsize Defaults to $db->maxblobsize if false
+ * @param bool $hastrans
+ * @return string|false The blob
+ */
+ function BlobDecode($blob, $maxsize=false, $hastrans=true)
{
if (!$this->GuessOID($blob)) return $blob;
@@ -429,7 +455,7 @@ class ADODB_postgres64 extends ADOConnection{
/**
* Encode binary value prior to DB storage.
*
- * See https://www.postgresql.org/docs/current/static/datatype-binary.html
+ * @link https://www.postgresql.org/docs/current/static/datatype-binary.html
*
* NOTE: SQL string literals (input strings) must be preceded with two
* backslashes due to the fact that they must pass through two parsers in
@@ -490,7 +516,6 @@ class ADODB_postgres64 extends ADOConnection{
global $ADODB_FETCH_MODE;
$schema = false;
- $false = false;
$this->_findschema($table,$schema);
if ($normalize) $table = strtolower($table);
@@ -504,7 +529,7 @@ class ADODB_postgres64 extends ADOConnection{
$ADODB_FETCH_MODE = $save;
if ($rs === false) {
- return $false;
+ return false;
}
if (!empty($this->metaKeySQL)) {
// If we want the primary keys, we have to issue a separate query
@@ -522,6 +547,8 @@ class ADODB_postgres64 extends ADOConnection{
$rskey->Close();
unset($rskey);
+ } else {
+ $keys = [];
}
$rsdefa = array();
@@ -574,28 +601,29 @@ class ADODB_postgres64 extends ADOConnection{
//Freek
$fld->not_null = $rs->fields[4] == 't';
-
// Freek
if (is_array($keys)) {
foreach($keys as $key) {
- if ($fld->name == $key['column_name'] AND $key['primary_key'] == 't')
+ if ($fld->name == $key['column_name'] && $key['primary_key'] == 't') {
$fld->primary_key = true;
- if ($fld->name == $key['column_name'] AND $key['unique_key'] == 't')
+ }
+ if ($fld->name == $key['column_name'] && $key['unique_key'] == 't') {
$fld->unique = true; // What name is more compatible?
+ }
}
}
- if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
- else $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld;
+ if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) {
+ $retarr[] = $fld;
+ }
+ else {
+ $retarr[($normalize) ? strtoupper($fld->name) : $fld->name] = $fld;
+ }
$rs->MoveNext();
}
$rs->Close();
- if (empty($retarr))
- return $false;
- else
- return $retarr;
-
+ return $retarr ?: false;
}
function param($name, $type='C')
@@ -639,7 +667,7 @@ class ADODB_postgres64 extends ADOConnection{
WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
}
- if ($primary == FALSE) {
+ if (!$primary) {
$sql .= ' AND i.indisprimary=false;';
}
@@ -656,8 +684,7 @@ class ADODB_postgres64 extends ADOConnection{
$ADODB_FETCH_MODE = $save;
if (!is_object($rs)) {
- $false = false;
- return $false;
+ return false;
}
// Get column names indexed by attnum so we can lookup the index key
@@ -748,22 +775,6 @@ class ADODB_postgres64 extends ADOConnection{
if ($this->_connectionID === false) return false;
$this->Execute("set datestyle='ISO'");
- $info = $this->ServerInfo(false);
-
- if (version_compare($info['version'], '7.1', '>=')) {
- $this->_nestedSQL = true;
- }
-
- # PostgreSQL 9.0 changed the default output for bytea from 'escape' to 'hex'
- # PHP does not handle 'hex' properly ('x74657374' is returned as 't657374')
- # https://bugs.php.net/bug.php?id=59831 states this is in fact not a bug,
- # so we manually set bytea_output
- if (version_compare($info['version'], '9.0', '>=')
- && version_compare($info['client'], '9.2', '<')
- ) {
- $this->Execute('set bytea_output=escape');
- }
-
return true;
}
@@ -910,17 +921,17 @@ class ADODB_postgres64 extends ADOConnection{
}
- /*
- * Maximum size of C field
- */
+ /**
+ * @return int Maximum size of C field
+ */
function CharMax()
{
return 1000000000; // should be 1 Gb?
}
- /*
- * Maximum size of X field
- */
+ /**
+ * @return int Maximum size of X field
+ */
function TextMax()
{
return 1000000000; // should be 1 Gb?
@@ -940,23 +951,21 @@ class ADORecordSet_postgres64 extends ADORecordSet{
function __construct($queryID, $mode=false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- switch ($mode)
- {
- case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break;
- case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break;
+ parent::__construct($queryID, $mode);
- case ADODB_FETCH_DEFAULT:
- case ADODB_FETCH_BOTH:
- default: $this->fetchMode = PGSQL_BOTH; break;
+ switch ($this->adodbFetchMode) {
+ case ADODB_FETCH_NUM:
+ $this->fetchMode = PGSQL_NUM;
+ break;
+ case ADODB_FETCH_ASSOC:
+ $this->fetchMode = PGSQL_ASSOC;
+ break;
+ case ADODB_FETCH_DEFAULT:
+ case ADODB_FETCH_BOTH:
+ default:
+ $this->fetchMode = PGSQL_BOTH;
+ break;
}
- $this->adodbFetchMode = $mode;
-
- // Parent's constructor
- parent::__construct($queryID);
}
function GetRowAssoc($upper = ADODB_ASSOC_CASE)
@@ -964,8 +973,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
if ($this->fetchMode == PGSQL_ASSOC && $upper == ADODB_ASSOC_CASE_LOWER) {
return $this->fields;
}
- $row = ADORecordSet::GetRowAssoc($upper);
- return $row;
+ return ADORecordSet::GetRowAssoc($upper);
}
function _initRS()
@@ -977,7 +985,6 @@ class ADORecordSet_postgres64 extends ADORecordSet{
// cache types for blob decode check
// apparently pg_field_type actually performs an sql query on the database to get the type.
- if (empty($this->connection->noBlobs))
for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) {
if (pg_field_type($qid,$i) == 'bytea') {
$this->_blobArr[$i] = pg_field_name($qid,$i);
@@ -1044,7 +1051,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
}
}
if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) {
- foreach($this->_blobArr as $k => $v) {
+ foreach($this->_blobArr as $v) {
$this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]);
}
}
@@ -1085,7 +1092,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
return pg_free_result($this->_queryID);
}
- function MetaType($t,$len=-1,$fieldobj=false)
+ function MetaType($t,$len=-1, $fieldObj=false)
{
if (is_object($t)) {
$fieldobj = $t;
@@ -1095,71 +1102,81 @@ class ADORecordSet_postgres64 extends ADORecordSet{
$t = strtoupper($t);
- if (array_key_exists($t,$this->connection->customActualTypes))
- return $this->connection->customActualTypes[$t];
+ if (array_key_exists($t, $this->connection->customActualTypes)) {
+ return $this->connection->customActualTypes[$t];
+ }
switch ($t) {
- case 'MONEY': // stupid, postgres expects money to be a string
- case 'INTERVAL':
- case 'CHAR':
- case 'CHARACTER':
- case 'VARCHAR':
- case 'NAME':
- case 'BPCHAR':
- case '_VARCHAR':
- case 'CIDR':
- case 'INET':
- case 'MACADDR':
- case 'UUID':
- if ($len <= $this->blobSize) return 'C';
-
- case 'TEXT':
- return 'X';
+ case 'MONEY': // stupid, postgres expects money to be a string
+ case 'INTERVAL':
+ case 'CHAR':
+ case 'CHARACTER':
+ case 'VARCHAR':
+ case 'NAME':
+ case 'BPCHAR':
+ case '_VARCHAR':
+ case 'CIDR':
+ case 'INET':
+ case 'MACADDR':
+ /** @noinspection PhpMissingBreakStatementInspection */
+ case 'UUID':
+ if ($len <= $this->blobSize) {
+ return 'C';
+ }
+ // Fall-through
- case 'IMAGE': // user defined type
- case 'BLOB': // user defined type
- case 'BIT': // This is a bit string, not a single bit, so don't return 'L'
- case 'VARBIT':
- case 'BYTEA':
- return 'B';
+ case 'TEXT':
+ return 'X';
- case 'BOOL':
- case 'BOOLEAN':
- return 'L';
+ case 'IMAGE': // user defined type
+ case 'BLOB': // user defined type
+ case 'BIT': // This is a bit string, not a single bit, so don't return 'L'
+ case 'VARBIT':
+ case 'BYTEA':
+ return 'B';
- case 'DATE':
- return 'D';
+ case 'BOOL':
+ case 'BOOLEAN':
+ return 'L';
+ case 'DATE':
+ return 'D';
- case 'TIMESTAMP WITHOUT TIME ZONE':
- case 'TIME':
- case 'DATETIME':
- case 'TIMESTAMP':
- case 'TIMESTAMPTZ':
- return 'T';
+ case 'TIMESTAMP WITHOUT TIME ZONE':
+ case 'TIME':
+ case 'DATETIME':
+ case 'TIMESTAMP':
+ case 'TIMESTAMPTZ':
+ return 'T';
- case 'SMALLINT':
- case 'BIGINT':
- case 'INTEGER':
- case 'INT8':
- case 'INT4':
- case 'INT2':
- if (isset($fieldobj) &&
- empty($fieldobj->primary_key) && (!$this->connection->uniqueIisR || empty($fieldobj->unique))) return 'I';
+ case 'SMALLINT':
+ case 'BIGINT':
+ case 'INTEGER':
+ case 'INT8':
+ case 'INT4':
+ /** @noinspection PhpMissingBreakStatementInspection */
+ case 'INT2':
+ if (isset($fieldobj)
+ && empty($fieldobj->primary_key)
+ && (!$this->connection->uniqueIisR || empty($fieldobj->unique))
+ ) {
+ return 'I';
+ }
+ // Fall-through
- case 'OID':
- case 'SERIAL':
- return 'R';
+ case 'OID':
+ case 'SERIAL':
+ return 'R';
- case 'NUMERIC':
- case 'DECIMAL':
- case 'FLOAT4':
- case 'FLOAT8':
- return 'N';
+ case 'NUMERIC':
+ case 'DECIMAL':
+ case 'FLOAT4':
+ case 'FLOAT8':
+ return 'N';
- default:
- return ADODB_DEFAULT_METATYPE;
- }
+ default:
+ return ADODB_DEFAULT_METATYPE;
+ }
}
}
diff --git a/drivers/adodb-sqlite.inc.php b/drivers/adodb-sqlite.inc.php
index d41829c0..00638e70 100644
--- a/drivers/adodb-sqlite.inc.php
+++ b/drivers/adodb-sqlite.inc.php
@@ -36,8 +36,8 @@ class ADODB_sqlite extends ADOConnection {
var $hasInsertID = true; /// supports autoincrement ID?
var $hasAffectedRows = true; /// supports affected rows for update/delete?
var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
- var $sysDate = "adodb_date('Y-m-d')";
- var $sysTimeStamp = "adodb_date('Y-m-d H:i:s')";
+ var $sysDate = "date('Y-m-d')";
+ var $sysTimeStamp = "date('Y-m-d H:i:s')";
var $fmtTimeStamp = "'Y-m-d H:i:s'";
function ServerInfo()
@@ -164,14 +164,12 @@ class ADODB_sqlite extends ADOConnection {
function SQLDate($fmt, $col=false)
{
$fmt = $this->qstr($fmt);
- return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)";
+ return ($col) ? "strftime($fmt,$col)" : "strftime($fmt)";
}
function _createFunctions()
{
- @sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1);
- @sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2);
}
@@ -425,14 +423,11 @@ class ADORecordset_sqlite extends ADORecordSet {
var $databaseType = "sqlite";
var $bind = false;
- function __construct($queryID,$mode=false)
+ function __construct($queryID, $mode=false)
{
+ parent::__construct($queryID, $mode);
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- switch($mode) {
+ switch ($this->adodbFetchMode) {
case ADODB_FETCH_NUM:
$this->fetchMode = SQLITE_NUM;
break;
@@ -443,9 +438,6 @@ class ADORecordset_sqlite extends ADORecordSet {
$this->fetchMode = SQLITE_BOTH;
break;
}
- $this->adodbFetchMode = $mode;
-
- $this->_queryID = $queryID;
$this->_inited = true;
$this->fields = array();
@@ -462,7 +454,6 @@ class ADORecordset_sqlite extends ADORecordSet {
return $this->_queryID;
}
-
function FetchField($fieldOffset = -1)
{
$fld = new ADOFieldObject;
diff --git a/drivers/adodb-sqlite3.inc.php b/drivers/adodb-sqlite3.inc.php
index 7e5f5ffd..e6bc9014 100644
--- a/drivers/adodb-sqlite3.inc.php
+++ b/drivers/adodb-sqlite3.inc.php
@@ -306,13 +306,11 @@ class ADODB_sqlite3 extends ADOConnection {
$fmt = str_replace($fromChars,$toChars,$fmt);
$fmt = $this->qstr($fmt);
- return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)";
+ return ($col) ? "strftime($fmt,$col)" : "strftime($fmt)";
}
function _createFunctions()
{
- $this->_connectionID->createFunction('adodb_date', 'adodb_date', 1);
- $this->_connectionID->createFunction('adodb_date2', 'adodb_date2', 2);
}
/** @noinspection PhpUnusedParameterInspection */
@@ -725,13 +723,10 @@ class ADORecordset_sqlite3 extends ADORecordSet {
var $_queryID;
/** @noinspection PhpMissingParentConstructorInspection */
- function __construct($queryID,$mode=false)
+ function __construct($queryID, $mode=false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- switch($mode) {
+ parent::__construct($queryID, $mode);
+ switch($this->adodbFetchMode) {
case ADODB_FETCH_NUM:
$this->fetchMode = SQLITE3_NUM;
break;
@@ -742,9 +737,6 @@ class ADORecordset_sqlite3 extends ADORecordSet {
$this->fetchMode = SQLITE3_BOTH;
break;
}
- $this->adodbFetchMode = $mode;
-
- $this->_queryID = $queryID;
$this->_inited = true;
$this->fields = array();
@@ -761,7 +753,6 @@ class ADORecordset_sqlite3 extends ADORecordSet {
return $this->_queryID;
}
-
function FetchField($fieldOffset = -1)
{
$fld = new ADOFieldObject;
diff --git a/drivers/adodb-sybase.inc.php b/drivers/adodb-sybase.inc.php
index 79fb82e8..abadb51c 100644
--- a/drivers/adodb-sybase.inc.php
+++ b/drivers/adodb-sybase.inc.php
@@ -315,15 +315,11 @@ class ADORecordset_sybase extends ADORecordSet {
// _mths works only in non-localised system
var $_mths = array('JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12);
- function __construct($id,$mode=false)
+ function __construct($queryID, $mode=false)
{
- if ($mode === false) {
- global $ADODB_FETCH_MODE;
- $mode = $ADODB_FETCH_MODE;
- }
- if (!$mode) $this->fetchMode = ADODB_FETCH_ASSOC;
- else $this->fetchMode = $mode;
- parent::__construct($id);
+ parent::__construct($queryID, $mode);
+
+ $this->fetchMode = $this->adodbFetchMode ?: ADODB_FETCH_ASSOC;
}
/* Returns: an object containing field information.
@@ -412,7 +408,7 @@ class ADORecordSet_array_sybase extends ADORecordSet_array {
$themth = $ADODB_sybase_mths[$themth];
if ($themth <= 0) return false;
// h-m-s-MM-DD-YY
- return adodb_mktime(0,0,0,$themth,$rr[2],$rr[3]);
+ return mktime(0,0,0,$themth,$rr[2],$rr[3]);
}
static function UnixTimeStamp($v)
@@ -439,6 +435,6 @@ class ADORecordSet_array_sybase extends ADORecordSet_array {
break;
}
// h-m-s-MM-DD-YY
- return adodb_mktime($rr[4],$rr[5],0,$themth,$rr[2],$rr[3]);
+ return mktime($rr[4],$rr[5],0,$themth,$rr[2],$rr[3]);
}
}