3 V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
4 Released under both BSD license and Lesser GPL library license.
5 Whenever there is any discrepancy between the two licenses,
6 the BSD license will take precedence.
9 MySQL code that does not support transactions. Use mysqlt if you need transactions.
10 Requires mysql client. Works on Windows and Unix.
12 21 October 2003: MySQLi extension implementation by Arjen de Rijke (a.de.rijke@xs4all.nl)
16 // security - hide paths
17 if (!defined('ADODB_DIR')) die();
19 if (! defined("_ADODB_MYSQLI_LAYER")) {
20 define("_ADODB_MYSQLI_LAYER", 1 );
23 if (! defined("MYSQLI_BINARY_FLAG")) define("MYSQLI_BINARY_FLAG", 128);
24 if (!defined('MYSQLI_READ_DEFAULT_GROUP')) define('MYSQLI_READ_DEFAULT_GROUP',1);
26 // disable adodb extension - currently incompatible.
27 global $ADODB_EXTENSION; $ADODB_EXTENSION = false;
29 class ADODB_mysqli
extends ADOConnection
{
30 var $databaseType = 'mysqli';
31 var $dataProvider = 'native';
32 var $hasInsertID = true;
33 var $hasAffectedRows = true;
34 var $metaTablesSQL = "SHOW TABLES";
35 var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
36 var $fmtTimeStamp = "'Y-m-d H:i:s'";
38 var $hasMoveFirst = true;
40 var $isoDates = true; // accepts dates in ISO format
41 var $sysDate = 'CURDATE()';
42 var $sysTimeStamp = 'NOW()';
43 var $hasTransactions = true;
44 var $forceNewConnect = false;
45 var $poorAffectedRows = true;
47 var $substr = "substring";
50 var $_bindInputArray = false;
51 var $nameQuote = '`'; /// string to use to quote identifiers and names
52 var $optionFlags = array(array(MYSQLI_READ_DEFAULT_GROUP
,0));
54 function ADODB_mysqli()
56 // if(!extension_loaded("mysqli"))
57 ;//trigger_error("You must have the mysqli extension installed.", E_USER_ERROR);
61 function SetTransactionMode( $transaction_mode )
63 $this->_transmode
= $transaction_mode;
64 if (empty($transaction_mode)) {
65 $this->Execute('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ');
68 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
69 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
72 // returns true or false
73 // To add: parameter int $port,
74 // parameter string $socket
75 function _connect($argHostname = NULL,
78 $argDatabasename = NULL, $persist=false)
80 if(!extension_loaded("mysqli")) {
83 $this->_connectionID
= @mysqli_init
();
85 if (is_null($this->_connectionID
)) {
86 // mysqli_init only fails if insufficient memory
88 ADOConnection
::outp("mysqli_init() failed : " . $this->ErrorMsg());
92 I suggest a simple fix which would enable adodb and mysqli driver to
93 read connection options from the standard mysql configuration file
94 /etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com>
96 foreach($this->optionFlags
as $arr) {
97 mysqli_options($this->_connectionID
,$arr[0],$arr[1]);
100 #if (!empty($this->port)) $argHostname .= ":".$this->port;
101 $ok = mysqli_real_connect($this->_connectionID
,
111 if ($argDatabasename) return $this->SelectDB($argDatabasename);
115 ADOConnection
::outp("Could't connect : " . $this->ErrorMsg());
120 // returns true or false
121 // How to force a persistent connection
122 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
124 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, true);
128 // When is this used? Close old connection first?
129 // In _connect(), check $this->forceNewConnect?
130 function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
132 $this->forceNewConnect
= true;
133 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
136 function IfNull( $field, $ifNull )
138 return " IFNULL($field, $ifNull) "; // if MySQL
141 // do not use $ADODB_COUNTRECS
142 function GetOne($sql,$inputarr=false)
145 $rs = &$this->Execute($sql,$inputarr);
147 if (!$rs->EOF
) $ret = reset($rs->fields
);
153 function ServerInfo()
155 $arr['description'] = $this->GetOne("select version()");
156 $arr['version'] = ADOConnection
::_findvers($arr['description']);
161 function BeginTrans()
163 if ($this->transOff
) return true;
164 $this->transCnt +
= 1;
166 //$this->Execute('SET AUTOCOMMIT=0');
167 mysqli_autocommit($this->_connectionID
, false);
168 $this->Execute('BEGIN');
172 function CommitTrans($ok=true)
174 if ($this->transOff
) return true;
175 if (!$ok) return $this->RollbackTrans();
177 if ($this->transCnt
) $this->transCnt
-= 1;
178 $this->Execute('COMMIT');
180 //$this->Execute('SET AUTOCOMMIT=1');
181 mysqli_autocommit($this->_connectionID
, true);
185 function RollbackTrans()
187 if ($this->transOff
) return true;
188 if ($this->transCnt
) $this->transCnt
-= 1;
189 $this->Execute('ROLLBACK');
190 //$this->Execute('SET AUTOCOMMIT=1');
191 mysqli_autocommit($this->_connectionID
, true);
195 function RowLock($tables,$where='',$flds='1 as adodb_ignore')
197 if ($this->transCnt
==0) $this->BeginTrans();
198 if ($where) $where = ' where '.$where;
199 $rs =& $this->Execute("select $flds from $tables $where for update");
203 // if magic quotes disabled, use mysql_real_escape_string()
205 // Quotes a string to be sent to the database. The $magic_quotes_enabled
206 // parameter may look funny, but the idea is if you are quoting a
207 // string extracted from a POST/GET variable, then
208 // pass get_magic_quotes_gpc() as the second parameter. This will
209 // ensure that the variable is not quoted twice, once by qstr and once
210 // by the magic_quotes_gpc.
212 //Eg. $s = $db->qstr(_GET['name'],get_magic_quotes_gpc());
213 function qstr($s, $magic_quotes = false)
215 if (!$magic_quotes) {
216 if (PHP_VERSION
>= 5)
217 return "'" . mysqli_real_escape_string($this->_connectionID
, $s) . "'";
219 if ($this->replaceQuote
[0] == '\\')
220 $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
221 return "'".str_replace("'",$this->replaceQuote
,$s)."'";
223 // undo magic quotes for "
224 $s = str_replace('\\"','"',$s);
230 $result = @mysqli_insert_id
($this->_connectionID
);
232 if ($this->debug
) ADOConnection
::outp("mysqli_insert_id() failed : " . $this->ErrorMsg());
237 // Only works for INSERT, UPDATE and DELETE query's
238 function _affectedrows()
240 $result = @mysqli_affected_rows
($this->_connectionID
);
242 if ($this->debug
) ADOConnection
::outp("mysqli_affected_rows() failed : " . $this->ErrorMsg());
247 // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
248 // Reference on Last_Insert_ID on the recommended way to simulate sequences
249 var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
250 var $_genSeqSQL = "create table %s (id int not null)";
251 var $_genSeq2SQL = "insert into %s values (%s)";
252 var $_dropSeqSQL = "drop table %s";
254 function CreateSequence($seqname='adodbseq',$startID=1)
256 if (empty($this->_genSeqSQL
)) return false;
257 $u = strtoupper($seqname);
259 $ok = $this->Execute(sprintf($this->_genSeqSQL
,$seqname));
260 if (!$ok) return false;
261 return $this->Execute(sprintf($this->_genSeq2SQL
,$seqname,$startID-1));
264 function GenID($seqname='adodbseq',$startID=1)
266 // post-nuke sets hasGenID to false
267 if (!$this->hasGenID
) return false;
269 $getnext = sprintf($this->_genIDSQL
,$seqname);
270 $holdtransOK = $this->_transOK
; // save the current status
271 $rs = @$this->Execute($getnext);
273 if ($holdtransOK) $this->_transOK
= true; //if the status was ok before reset
274 $u = strtoupper($seqname);
275 $this->Execute(sprintf($this->_genSeqSQL
,$seqname));
276 $cnt = $this->GetOne(sprintf($this->_genSeqCountSQL
,$seqname));
277 if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL
,$seqname,$startID-1));
278 $rs = $this->Execute($getnext);
282 $this->genID
= mysqli_insert_id($this->_connectionID
);
290 function &MetaDatabases()
292 $query = "SHOW DATABASES";
293 $ret =& $this->Execute($query);
294 if ($ret && is_object($ret)){
297 $db = $ret->Fields('Database');
298 if ($db != 'mysql') $arr[] = $db;
307 function &MetaIndexes ($table, $primary = FALSE)
309 // save old fetch mode
310 global $ADODB_FETCH_MODE;
313 $save = $ADODB_FETCH_MODE;
314 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
315 if ($this->fetchMode
!== FALSE) {
316 $savem = $this->SetFetchMode(FALSE);
320 $rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table));
324 $this->SetFetchMode($savem);
326 $ADODB_FETCH_MODE = $save;
328 if (!is_object($rs)) {
334 // parse index data into array
335 while ($row = $rs->FetchRow()) {
336 if ($primary == FALSE AND $row[2] == 'PRIMARY') {
340 if (!isset($indexes[$row[2]])) {
341 $indexes[$row[2]] = array(
342 'unique' => ($row[1] == 0),
347 $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
350 // sort columns by order in the index
351 foreach ( array_keys ($indexes) as $index )
353 ksort ($indexes[$index]['columns']);
360 // Format date column in sql string given an input format that understands Y M D
361 function SQLDate($fmt, $col=false)
363 if (!$col) $col = $this->sysTimeStamp
;
364 $s = 'DATE_FORMAT('.$col.",'";
367 for ($i=0; $i < $len; $i++
) {
376 $s .= "'),Quarter($col)";
378 if ($len > $i+
1) $s .= ",DATE_FORMAT($col,'";
427 $ch = substr($fmt,$i,1);
434 if ($concat) $s = "CONCAT($s)";
438 // returns concatenated string
439 // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
443 $arr = func_get_args();
445 // suggestion by andrew005@mnogo.ru
446 $s = implode(',',$arr);
447 if (strlen($s) > 0) return "CONCAT($s)";
451 // dayFraction is a day in floating point
452 function OffsetDate($dayFraction,$date=false)
454 if (!$date) $date = $this->sysDate
;
456 $fraction = $dayFraction * 24 * 3600;
457 return $date . ' + INTERVAL ' . $fraction.' SECOND';
459 // return "from_unixtime(unix_timestamp($date)+$fraction)";
462 function &MetaTables($ttype=false,$showSchema=false,$mask=false)
464 $save = $this->metaTablesSQL
;
465 if ($showSchema && is_string($showSchema)) {
466 $this->metaTablesSQL
.= " from $showSchema";
470 $mask = $this->qstr($mask);
471 $this->metaTablesSQL
.= " like $mask";
473 $ret =& ADOConnection
::MetaTables($ttype,$showSchema);
475 $this->metaTablesSQL
= $save;
479 // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx>
480 function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE )
482 global $ADODB_FETCH_MODE;
484 if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC ||
$this->fetchMode
== ADODB_FETCH_ASSOC
) $associative = true;
486 if ( !empty($owner) ) {
487 $table = "$owner.$table";
489 $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
490 if ($associative) $create_sql = $a_create_table["Create Table"];
491 else $create_sql = $a_create_table[1];
495 if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches)) return false;
496 $foreign_keys = array();
497 $num_keys = count($matches[0]);
498 for ( $i = 0; $i < $num_keys; $i ++
) {
499 $my_field = explode('`, `', $matches[1][$i]);
500 $ref_table = $matches[2][$i];
501 $ref_field = explode('`, `', $matches[3][$i]);
504 $ref_table = strtoupper($ref_table);
507 $foreign_keys[$ref_table] = array();
508 $num_fields = count($my_field);
509 for ( $j = 0; $j < $num_fields; $j ++
) {
510 if ( $associative ) {
511 $foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
513 $foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}";
518 return $foreign_keys;
521 function &MetaColumns($table)
524 if (!$this->metaColumnsSQL
)
527 global $ADODB_FETCH_MODE;
528 $save = $ADODB_FETCH_MODE;
529 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
530 if ($this->fetchMode
!== false)
531 $savem = $this->SetFetchMode(false);
532 $rs = $this->Execute(sprintf($this->metaColumnsSQL
,$table));
533 if (isset($savem)) $this->SetFetchMode($savem);
534 $ADODB_FETCH_MODE = $save;
540 $fld = new ADOFieldObject();
541 $fld->name
= $rs->fields
[0];
542 $type = $rs->fields
[1];
544 // split type into type(length):
546 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
547 $fld->type
= $query_array[1];
548 $fld->max_length
= is_numeric($query_array[2]) ?
$query_array[2] : -1;
549 $fld->scale
= is_numeric($query_array[3]) ?
$query_array[3] : -1;
550 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
551 $fld->type
= $query_array[1];
552 $fld->max_length
= is_numeric($query_array[2]) ?
$query_array[2] : -1;
553 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
554 $fld->type
= $query_array[1];
555 $fld->max_length
= max(array_map("strlen",explode(",",$query_array[2]))) - 2; // PHP >= 4.0.6
556 $fld->max_length
= ($fld->max_length
== 0 ?
1 : $fld->max_length
);
559 $fld->max_length
= -1;
561 $fld->not_null
= ($rs->fields
[2] != 'YES');
562 $fld->primary_key
= ($rs->fields
[3] == 'PRI');
563 $fld->auto_increment
= (strpos($rs->fields
[5], 'auto_increment') !== false);
564 $fld->binary
= (strpos($type,'blob') !== false);
565 $fld->unsigned
= (strpos($type,'unsigned') !== false);
566 $fld->zerofill
= (strpos($type,'zerofill') !== false);
570 if ($d != '' && $d != 'NULL') {
571 $fld->has_default
= true;
572 $fld->default_value
= $d;
574 $fld->has_default
= false;
578 if ($save == ADODB_FETCH_NUM
) {
581 $retarr[strtoupper($fld->name
)] = $fld;
590 // returns true or false
591 function SelectDB($dbName)
593 // $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
594 $this->database
= $dbName;
595 $this->databaseName
= $dbName; # obsolete, retained for compat with older adodb versions
597 if ($this->_connectionID
) {
598 $result = @mysqli_select_db
($this->_connectionID
, $dbName);
600 ADOConnection
::outp("Select of database " . $dbName . " failed. " . $this->ErrorMsg());
607 // parameters use PostgreSQL convention, not MySQL
608 function &SelectLimit($sql,
615 $offsetStr = ($offset >= 0) ?
"$offset," : '';
616 if ($nrows < 0) $nrows = '18446744073709551615';
619 $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
621 $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
627 function Prepare($sql)
631 $stmt = $this->_connectionID
->prepare($sql);
633 echo $this->ErrorMsg();
636 return array($sql,$stmt);
640 // returns queryID or false
641 function _query($sql, $inputarr)
643 global $ADODB_COUNTRECS;
645 if (is_array($sql)) {
648 foreach($inputarr as $k => $v) {
649 if (is_string($v)) $a .= 's';
650 else if (is_integer($v)) $a .= 'i';
654 $fnarr = array_merge( array($stmt,$a) , $inputarr);
655 $ret = call_user_func_array('mysqli_stmt_bind_param',$fnarr);
657 $ret = mysqli_stmt_execute($stmt);
660 if (!$mysql_res = mysqli_query($this->_connectionID
, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT
: MYSQLI_USE_RESULT
)) {
661 if ($this->debug
) ADOConnection
::outp("Query: " . $sql . " failed. " . $this->ErrorMsg());
668 /* Returns: the last error message from previous database operation */
671 if (empty($this->_connectionID
))
672 $this->_errorMsg
= @mysqli_connect_error
();
674 $this->_errorMsg
= @mysqli_error
($this->_connectionID
);
675 return $this->_errorMsg
;
678 /* Returns: the last error number from previous database operation */
681 if (empty($this->_connectionID
))
682 return @mysqli_connect_errno
();
684 return @mysqli_errno
($this->_connectionID
);
687 // returns true or false
690 @mysqli_close
($this->_connectionID
);
691 $this->_connectionID
= false;
695 * Maximum size of C field
703 * Maximum size of X field
712 // this is a set of functions for managing client encoding - very important if the encodings
713 // of your database and your output target (i.e. HTML) don't match
714 // for instance, you may have UTF8 database and server it on-site as latin1 etc.
715 // GetCharSet - get the name of the character set the client is using now
716 // Under Windows, the functions should work with MySQL 4.1.11 and above, the set of charsets supported
717 // depends on compile flags of mysql distribution
719 function GetCharSet()
721 //we will use ADO's builtin property charSet
722 if (!method_exists($this->_connectionID
,'character_set_name'))
725 $this->charSet
= @$this->_connectionID
->character_set_name();
726 if (!$this->charSet
) {
729 return $this->charSet
;
733 // SetCharSet - switch the client encoding
734 function SetCharSet($charset_name)
736 if (!method_exists($this->_connectionID
,'set_charset'))
739 if ($this->charSet
!== $charset_name) {
740 $if = @$this->_connectionID
->set_charset($charset_name);
741 if ($if == "0" & $this->GetCharSet() == $charset_name) {
752 /*--------------------------------------------------------------------------------------
753 Class Name: Recordset
754 --------------------------------------------------------------------------------------*/
756 class ADORecordSet_mysqli
extends ADORecordSet
{
758 var $databaseType = "mysqli";
761 function ADORecordSet_mysqli($queryID, $mode = false)
765 global $ADODB_FETCH_MODE;
766 $mode = $ADODB_FETCH_MODE;
771 case ADODB_FETCH_NUM
:
772 $this->fetchMode
= MYSQLI_NUM
;
774 case ADODB_FETCH_ASSOC
:
775 $this->fetchMode
= MYSQLI_ASSOC
;
777 case ADODB_FETCH_DEFAULT
:
778 case ADODB_FETCH_BOTH
:
780 $this->fetchMode
= MYSQLI_BOTH
;
783 $this->adodbFetchMode
= $mode;
784 $this->ADORecordSet($queryID);
789 global $ADODB_COUNTRECS;
791 $this->_numOfRows
= $ADODB_COUNTRECS ? @mysqli_num_rows
($this->_queryID
) : -1;
792 $this->_numOfFields
= @mysqli_num_fields
($this->_queryID
);
796 1 = MYSQLI_NOT_NULL_FLAG
797 2 = MYSQLI_PRI_KEY_FLAG
798 4 = MYSQLI_UNIQUE_KEY_FLAG
799 8 = MYSQLI_MULTIPLE_KEY_FLAG
800 16 = MYSQLI_BLOB_FLAG
801 32 = MYSQLI_UNSIGNED_FLAG
802 64 = MYSQLI_ZEROFILL_FLAG
803 128 = MYSQLI_BINARY_FLAG
804 256 = MYSQLI_ENUM_FLAG
805 512 = MYSQLI_AUTO_INCREMENT_FLAG
806 1024 = MYSQLI_TIMESTAMP_FLAG
807 2048 = MYSQLI_SET_FLAG
808 32768 = MYSQLI_NUM_FLAG
809 16384 = MYSQLI_PART_KEY_FLAG
810 32768 = MYSQLI_GROUP_FLAG
811 65536 = MYSQLI_UNIQUE_FLAG
812 131072 = MYSQLI_BINCMP_FLAG
815 function &FetchField($fieldOffset = -1)
817 $fieldnr = $fieldOffset;
818 if ($fieldOffset != -1) {
819 $fieldOffset = mysqli_field_seek($this->_queryID
, $fieldnr);
821 $o = mysqli_fetch_field($this->_queryID
);
822 /* Properties of an ADOFieldObject as set by MetaColumns */
823 $o->primary_key
= $o->flags
& MYSQLI_PRI_KEY_FLAG
;
824 $o->not_null
= $o->flags
& MYSQLI_NOT_NULL_FLAG
;
825 $o->auto_increment
= $o->flags
& MYSQLI_AUTO_INCREMENT_FLAG
;
826 $o->binary
= $o->flags
& MYSQLI_BINARY_FLAG
;
827 // $o->blob = $o->flags & MYSQLI_BLOB_FLAG; /* not returned by MetaColumns */
828 $o->unsigned
= $o->flags
& MYSQLI_UNSIGNED_FLAG
;
833 function &GetRowAssoc($upper = true)
835 if ($this->fetchMode
== MYSQLI_ASSOC
&& !$upper)
836 return $this->fields
;
837 $row =& ADORecordSet
::GetRowAssoc($upper);
841 /* Use associative array to get fields array */
842 function Fields($colname)
844 if ($this->fetchMode
!= MYSQLI_NUM
)
845 return @$this->fields
[$colname];
848 $this->bind
= array();
849 for ($i = 0; $i < $this->_numOfFields
; $i++
) {
850 $o = $this->FetchField($i);
851 $this->bind
[strtoupper($o->name
)] = $i;
854 return $this->fields
[$this->bind
[strtoupper($colname)]];
859 if ($this->_numOfRows
== 0)
865 mysqli_data_seek($this->_queryID
, $row);
870 // 10% speedup to move MoveNext to child class
871 // This is the only implementation that works now (23-10-2003).
872 // Other functions return no or the wrong results.
875 if ($this->EOF
) return false;
876 $this->_currentRow++
;
877 $this->fields
= @mysqli_fetch_array
($this->_queryID
,$this->fetchMode
);
879 if (is_array($this->fields
)) return true;
886 $this->fields
= mysqli_fetch_array($this->_queryID
,$this->fetchMode
);
887 return is_array($this->fields
);
892 mysqli_free_result($this->_queryID
);
893 $this->_queryID
= false;
898 0 = MYSQLI_TYPE_DECIMAL
901 2 = MYSQLI_TYPE_SHORT
903 4 = MYSQLI_TYPE_FLOAT
904 5 = MYSQLI_TYPE_DOUBLE
906 7 = MYSQLI_TYPE_TIMESTAMP
907 8 = MYSQLI_TYPE_LONGLONG
908 9 = MYSQLI_TYPE_INT24
909 10 = MYSQLI_TYPE_DATE
910 11 = MYSQLI_TYPE_TIME
911 12 = MYSQLI_TYPE_DATETIME
912 13 = MYSQLI_TYPE_YEAR
913 14 = MYSQLI_TYPE_NEWDATE
914 247 = MYSQLI_TYPE_ENUM
915 248 = MYSQLI_TYPE_SET
916 249 = MYSQLI_TYPE_TINY_BLOB
917 250 = MYSQLI_TYPE_MEDIUM_BLOB
918 251 = MYSQLI_TYPE_LONG_BLOB
919 252 = MYSQLI_TYPE_BLOB
920 253 = MYSQLI_TYPE_VAR_STRING
921 254 = MYSQLI_TYPE_STRING
922 255 = MYSQLI_TYPE_GEOMETRY
925 function MetaType($t, $len = -1, $fieldobj = false)
929 $t = $fieldobj->type
;
930 $len = $fieldobj->max_length
;
934 $len = -1; // mysql max_length is not accurate
935 switch (strtoupper($t)) {
944 case MYSQLI_TYPE_TINY_BLOB
:
945 case MYSQLI_TYPE_CHAR
:
946 case MYSQLI_TYPE_STRING
:
947 case MYSQLI_TYPE_ENUM
:
948 case MYSQLI_TYPE_SET
:
950 if ($len <= $this->blobSize
) return 'C';
958 // php_mysql extension always returns 'blob' even if 'text'
959 // so we have to check whether binary...
965 case MYSQLI_TYPE_BLOB
:
966 case MYSQLI_TYPE_LONG_BLOB
:
967 case MYSQLI_TYPE_MEDIUM_BLOB
:
969 return !empty($fieldobj->binary
) ?
'B' : 'X';
972 case MYSQLI_TYPE_DATE
:
973 case MYSQLI_TYPE_YEAR
:
981 case MYSQLI_TYPE_DATETIME
:
982 case MYSQLI_TYPE_NEWDATE
:
983 case MYSQLI_TYPE_TIME
:
984 case MYSQLI_TYPE_TIMESTAMP
:
995 case MYSQLI_TYPE_INT24
:
996 case MYSQLI_TYPE_LONG
:
997 case MYSQLI_TYPE_LONGLONG
:
998 case MYSQLI_TYPE_SHORT
:
999 case MYSQLI_TYPE_TINY
:
1001 if (!empty($fieldobj->primary_key
)) return 'R';
1006 // Added floating-point types
1007 // Maybe not necessery.
1010 // case 'DOUBLE PRECISION':
1015 //if (!is_numeric($t)) echo "<p>--- Error in type matching $t -----</p>";