Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+43 -49
View File
@@ -100,7 +100,7 @@ class Db extends \mysqli
}
/* Connect */
$classname = get_called_class();
$classname = \get_called_class();
self::$multitons[ $identifier ] = @new $classname(
$connectionSettings['sql_host'],
$connectionSettings['sql_user'],
@@ -287,7 +287,7 @@ class Db extends \mysqli
foreach ( $binds as $bindVal )
{
$i++;
switch ( gettype( $bindVal ) )
switch ( \gettype( $bindVal ) )
{
case 'boolean':
case 'integer':
@@ -356,7 +356,7 @@ class Db extends \mysqli
/* Bind values */
if( $bind->haveBinds() === TRUE )
{
call_user_func_array( array( $stmt, 'bind_param' ), $bind->get() );
$stmt->bind_param( ...$bind->get() );
}
/* Execute */
@@ -372,7 +372,6 @@ class Db extends \mysqli
}
const SELECT_DISTINCT = 1;
const SELECT_SQL_CALC_FOUND_ROWS = 2;
/**
* Build SELECT statement
@@ -386,7 +385,6 @@ class Db extends \mysqli
* @param array|string|NULL $having HAVING clause (same format as WHERE clause)
* @param int $flags Bitwise flags
* @li \IPSUtf8\Db::SELECT_DISTINCT Will use SELECT DISTINCT
* @li \IPSUtf8\DB::SELECT_SQL_CALC_FOUND_ROWS Will add SQL_CALC_FOUND_ROWS
* @return \IPSUtf8\Db\Select
*
*/
@@ -400,13 +398,9 @@ class Db extends \mysqli
{
$query .= 'DISTINCT ';
}
if ( $flags & static::SELECT_SQL_CALC_FOUND_ROWS )
{
$query .= 'SQL_CALC_FOUND_ROWS ';
}
/* Columns */
if ( is_string( $columns ) )
if ( \is_string( $columns ) )
{
$query .= $columns;
}
@@ -419,7 +413,7 @@ class Db extends \mysqli
}
/* Tables */
if ( is_array( $table ) )
if ( \is_array( $table ) )
{
$query .= " FROM `{$this->prefix}{$table[0]}` AS `{$table[1]}`";
}
@@ -530,7 +524,7 @@ class Db extends \mysqli
/* Is this just one row? */
foreach ( $set as $k => $v )
{
if ( !is_array( $v ) )
if ( !\is_array( $v ) )
{
$set = array( $set );
}
@@ -548,7 +542,7 @@ class Db extends \mysqli
$columns = array_map( function( $val ){ return "`{$val}`"; }, array_keys( $row ) );
}
if ( count( $set ) > 1 AND $bulkInsertNoPrep )
if ( \count( $set ) > 1 AND $bulkInsertNoPrep )
{
if ( $tableDefinition === NULL )
{
@@ -559,7 +553,7 @@ class Db extends \mysqli
{
if ( isset( $tableDefinition['definition']['columns'][ $k ] ) )
{
$isInt = in_array( \mb_strtolower( $tableDefinition['definition']['columns'][ $k ]['type'] ), array( 'integer', 'int', 'smallint', 'tinyint', 'mediumint', 'bigint', 'decimal', 'numeric', 'float', 'double' ) );
$isInt = \in_array( \mb_strtolower( $tableDefinition['definition']['columns'][ $k ]['type'] ), array( 'integer', 'int', 'smallint', 'tinyint', 'mediumint', 'bigint', 'decimal', 'numeric', 'float', 'double' ) );
if ( $isInt )
{
@@ -616,7 +610,7 @@ class Db extends \mysqli
else
{
$binds = array_merge( $binds, array_values( $row ) );
$values[] = '( ' . implode( ', ', array_fill( 0, count( $columns ), '?' ) ) . ' )';
$values[] = '( ' . implode( ', ', array_fill( 0, \count( $columns ), '?' ) ) . ' )';
}
}
@@ -631,7 +625,7 @@ class Db extends \mysqli
}
/* Run */
if ( count( $set ) > 1 AND $bulkInsertNoPrep )
if ( \count( $set ) > 1 AND $bulkInsertNoPrep )
{
$stmt = $this->query( $query );
return $this->insert_id;
@@ -655,7 +649,7 @@ class Db extends \mysqli
public function replace( $table, $set )
{
$columns = implode( ', ', array_map( function( $val ){ return "`{$val}`"; }, array_keys( $set ) ) );
$query = "REPLACE INTO `{$this->prefix}{$table}` ( " . $columns . " ) VALUES ( " . implode( ', ', array_fill( 0, count( $set ), '?' ) ) . " )";
$query = "REPLACE INTO `{$this->prefix}{$table}` ( " . $columns . " ) VALUES ( " . implode( ', ', array_fill( 0, \count( $set ), '?' ) ) . " )";
$stmt = $this->preparedQuery( $query, array_values( $set ) );
return $stmt->affected_rows;
@@ -678,13 +672,13 @@ class Db extends \mysqli
$binds = array();
/* Work out table */
$table = is_array( $table ) ? "`{$this->prefix}{$table[0]}` {$this->prefix}{$table[1]}" : "`{$this->prefix}{$table}`";
$table = \is_array( $table ) ? "`{$this->prefix}{$table[0]}` {$this->prefix}{$table[1]}" : "`{$this->prefix}{$table}`";
/* Work out joins */
foreach ( $joins as $join )
{
$type = ( isset( $join['type'] ) and in_array( strtoupper( $join['type'] ), array( 'LEFT', 'INNER', 'RIGHT' ) ) ) ? strtoupper( $join['type'] ) : 'LEFT';
$_table = is_array( $join['from'] ) ? "`{$this->prefix}{$join['from'][0]}` {$this->prefix}{$join['from'][1]}" : $join['from'];
$type = ( isset( $join['type'] ) and \in_array( strtoupper( $join['type'] ), array( 'LEFT', 'INNER', 'RIGHT' ) ) ) ? strtoupper( $join['type'] ) : 'LEFT';
$_table = \is_array( $join['from'] ) ? "`{$this->prefix}{$join['from'][0]}` {$this->prefix}{$join['from'][1]}" : $join['from'];
$on = $this->compileWhereClause( $join['where'] );
$binds = array_merge( $binds, $on['binds'] );
@@ -694,7 +688,7 @@ class Db extends \mysqli
$joins = empty( $joins ) ? '' : ( ' ' . implode( "\n", $joins ) );
/* Work out SET clause */
if ( is_array( $set ) )
if ( \is_array( $set ) )
{
$_set = array();
foreach ( $set as $k => $v )
@@ -782,13 +776,13 @@ class Db extends \mysqli
{
$return = array( 'clause' => '1=1', 'binds' => array() );
if( is_string( $data ) )
if( \is_string( $data ) )
{
$return['clause'] = $data;
}
elseif ( is_array( $data ) and ! empty( $data ) )
elseif ( \is_array( $data ) and ! empty( $data ) )
{
if ( is_string( $data[0] ) )
if ( \is_string( $data[0] ) )
{
$data = array( $data );
}
@@ -796,7 +790,7 @@ class Db extends \mysqli
$clauses = array();
foreach ( $data as $bit )
{
if( !is_array( $bit ) )
if( !\is_array( $bit ) )
{
$clauses[] = $bit;
}
@@ -822,14 +816,14 @@ class Db extends \mysqli
protected function compileLimitClause( $data )
{
$limit = NULL;
if( is_array( $data ) )
if( \is_array( $data ) )
{
$offset = intval( $data[0] );
$limit = intval( $data[1] );
$offset = \intval( $data[0] );
$limit = \intval( $data[1] );
}
else
{
$offset = intval( $data );
$offset = \intval( $data );
}
if( $limit !== NULL )
@@ -875,18 +869,18 @@ class Db extends \mysqli
/* Some types specify length */
if(
in_array( $data['type'], array( 'VARCHAR', 'VARBINARY' ) )
\in_array( $data['type'], array( 'VARCHAR', 'VARBINARY' ) )
or
(
isset( $data['length'] ) and $data['length']
and
in_array( $data['type'], array( 'BIT', 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC', 'CHAR', 'BINARY' ) )
\in_array( $data['type'], array( 'BIT', 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC', 'CHAR', 'BINARY' ) )
)
) {
$definition .= "({$data['length']}";
/* And some of those specify decimals (which may or may not be optional) */
if( in_array( $data['type'], array( 'REAL', 'DOUBLE', 'FLOAT' ) ) or ( in_array( $data['type'], array( 'DECIMAL', 'NUMERIC' ) ) and isset( $data['decimals'] ) ) )
if( \in_array( $data['type'], array( 'REAL', 'DOUBLE', 'FLOAT' ) ) or ( \in_array( $data['type'], array( 'DECIMAL', 'NUMERIC' ) ) and isset( $data['decimals'] ) ) )
{
$definition .= ',' . $data['decimals'];
}
@@ -895,7 +889,7 @@ class Db extends \mysqli
}
/* Numeric types can be UNSIGNED and ZEROFILL */
if( in_array( $data['type'], array( 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC' ) ) )
if( \in_array( $data['type'], array( 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC' ) ) )
{
if( isset( $data['unsigned'] ) and $data['unsigned'] === TRUE )
{
@@ -908,7 +902,7 @@ class Db extends \mysqli
}
/* ENUM and SETs have values */
if( in_array( $data['type'], array( 'ENUM', 'SET' ) ) )
if( \in_array( $data['type'], array( 'ENUM', 'SET' ) ) )
{
$values = array();
foreach ( $data['values'] as $v )
@@ -920,13 +914,13 @@ class Db extends \mysqli
}
/* Some types can be binary or not */
if( isset( $data['binary'] ) and $data['binary'] === TRUE and in_array( $data['type'], array( 'CHAR', 'VARCHAR', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT' ) ) )
if( isset( $data['binary'] ) and $data['binary'] === TRUE and \in_array( $data['type'], array( 'CHAR', 'VARCHAR', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT' ) ) )
{
$definition .= 'BINARY ';
}
/* Text types specify a character set and collation */
if( in_array( $data['type'], array( 'CHAR', 'VARCHAR', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'ENUM', 'SET' ) ) )
if( \in_array( $data['type'], array( 'CHAR', 'VARCHAR', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'ENUM', 'SET' ) ) )
{
$definition .= "CHARACTER SET {$this->charset} COLLATE {$this->collation} ";
}
@@ -942,13 +936,13 @@ class Db extends \mysqli
}
/* Default value */
if( isset( $data['default'] ) and !in_array( $data['type'], array( 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'BLOB', 'MEDIUMBLOB', 'BIGBLOB' ) ) )
if( isset( $data['default'] ) and !\in_array( $data['type'], array( 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'BLOB', 'MEDIUMBLOB', 'BIGBLOB' ) ) )
{
$defaultValue = in_array( $data['type'], array( 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC', 'BIT' ) ) ? floatval( $data['default'] ) : ( ! in_array( $data['default'], array( 'CURRENT_TIMESTAMP' ) ) ? '\'' . $this->escape_string( $data['default'] ) . '\'' : $data['default'] );
$defaultValue = \in_array( $data['type'], array( 'TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER', 'BIGINT', 'REAL', 'DOUBLE', 'FLOAT', 'DECIMAL', 'NUMERIC', 'BIT' ) ) ? \floatval( $data['default'] ) : ( ! \in_array( $data['default'], array( 'CURRENT_TIMESTAMP' ) ) ? '\'' . $this->escape_string( $data['default'] ) . '\'' : $data['default'] );
/* Strict Mode isn't nice */
$toTest = trim( $defaultValue, "'" );
if ( in_array( $data['type'], array( 'DATETIME' ) ) AND empty( $toTest ) ) # array here in case we need to expand later
if ( \in_array( $data['type'], array( 'DATETIME' ) ) AND empty( $toTest ) ) # array here in case we need to expand later
{
$defaultValue = '\'0000-00-00 00:00:00\'';
}
@@ -1030,7 +1024,7 @@ class Db extends \mysqli
$definition .= '(' . implode( ',', array_map( function ( $val, $len )
{
return ( ! empty( $len ) ) ? "`{$val}`({$len})" : "`{$val}`";
}, $data['columns'], ( ( isset( $data['length'] ) AND is_array( $data['length'] ) ) ? $data['length'] : array_fill( 0, count( $data['columns'] ), null ) ) ) ) . ')';
}, $data['columns'], ( ( isset( $data['length'] ) AND \is_array( $data['length'] ) ) ? $data['length'] : array_fill( 0, \count( $data['columns'] ), null ) ) ) ) . ')';
/* Return */
return $definition;
@@ -1199,7 +1193,7 @@ class Db extends \mysqli
{
return '`' . $prefix . $val . '`';
},
( is_array( $table ) ? $table : array( $table ) )
( \is_array( $table ) ? $table : array( $table ) )
) )
);
}
@@ -1260,10 +1254,10 @@ class Db extends \mysqli
else
{
$lengthInfo = explode( ',', $matches[2] );
$columnDefinition['length'] = intval( $lengthInfo[0] );
$columnDefinition['length'] = \intval( $lengthInfo[0] );
if( isset( $lengthInfo[1] ) )
{
$columnDefinition['decimals'] = intval( $lengthInfo[1] );
$columnDefinition['decimals'] = \intval( $lengthInfo[1] );
}
}
}
@@ -1276,10 +1270,10 @@ class Db extends \mysqli
}
/* unsigned? */
$columnDefinition['unsigned'] = in_array( 'unsigned', $typeInfo );
$columnDefinition['unsigned'] = \in_array( 'unsigned', $typeInfo );
/* zerofill? */
$columnDefinition['zerofill'] = in_array( 'zerofill', $typeInfo );
$columnDefinition['zerofill'] = \in_array( 'zerofill', $typeInfo );
/* binary? */
$columnDefinition['binary'] = ( $row['Collation'] === $this->binaryCollation );
@@ -1313,7 +1307,7 @@ class Db extends \mysqli
$query = $this->query( "SHOW INDEXES FROM `{$this->prefix}{$table}`" );
while ( $row = $query->fetch_assoc() )
{
$length = ( isset( $row['Sub_part'] ) AND ! empty( $row['Sub_part'] ) ) ? intval( $row['Sub_part'] ) : null;
$length = ( isset( $row['Sub_part'] ) AND ! empty( $row['Sub_part'] ) ) ? \intval( $row['Sub_part'] ) : null;
if( isset( $indexes[ $row['Key_name'] ] ) )
{
@@ -1499,11 +1493,11 @@ class Db extends \mysqli
foreach( $values as $i )
{
if ( $i and is_numeric( $i ) )
if ( $i and \is_numeric( $i ) )
{
$where[] = "FIND_IN_SET(" . $i . "," . $column . ")";
}
else if ( $i and is_string( $i ) )
else if ( $i and \is_string( $i ) )
{
$in[] = "'" . $this->real_escape_string( $i ) . "'";
}
@@ -1521,7 +1515,7 @@ class Db extends \mysqli
$return[] = $column . ' IN(' . implode( ',', $in ) . ')';
}
if ( count( $return ) )
if ( \count( $return ) )
{
return '(' . implode( ' OR ', $return ) . ')';
}