4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2012 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
14 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
15 * @copyright Copyright (C) 2012 The Nucleus Group
\r
19 if ( !class_exists('PDO') )
\r
23 * Dummy constant of the PDO class
\r
27 /* constant values */
\r
28 const PARAM_NULL = 0;
\r
29 const PARAM_INT = 1;
\r
30 const PARAM_STR = 2;
\r
31 const PARAM_LOB = 3;
\r
32 const PARAM_STMT = 4;
\r
33 const PARAM_BOOL = 5;
\r
34 const PARAM_INPUT_OUTPUT = 128; // orignal is undefined.
\r
35 const FETCH_LAZY = 1;
\r
36 const FETCH_ASSOC = 2;
\r
37 const FETCH_NUM = 3;
\r
38 const FETCH_BOTH = 4;
\r
39 const FETCH_OBJ = 5;
\r
40 const FETCH_BOUND = 6;
\r
41 const FETCH_COLUMN = 7;
\r
42 const FETCH_CLASS = 8;
\r
43 const FETCH_INTO = 9;
\r
44 const FETCH_FUNC = 10;
\r
45 const FETCH_NAMED = 11;
\r
46 const FETCH_KEY_PAIR = 12;
\r
47 const FETCH_GROUP = 65536;
\r
48 const FETCH_UNIQUE = 196608;
\r
49 const FETCH_CLASSTYPE = 262144;
\r
50 const FETCH_SERIALIZE = 524288;
\r
51 const FETCH_PROPS_LATE = 1048576;
\r
52 const ATTR_AUTOCOMMIT = 0;
\r
53 const ATTR_PREFETCH = 1;
\r
54 const ATTR_TIMEOUT = 2;
\r
55 const ATTR_ERRMODE = 3;
\r
56 const ATTR_SERVER_VERSION = 4;
\r
57 const ATTR_CLIENT_VERSION = 5;
\r
58 const ATTR_SERVER_INFO = 6;
\r
59 const ATTR_CONNECTION_STATUS = 7;
\r
60 const ATTR_CASE = 8;
\r
61 const ATTR_CURSOR_NAME = 9;
\r
62 const ATTR_CURSOR = 10;
\r
63 const ATTR_ORACLE_NULLS = 11;
\r
64 const ATTR_PERSISTENT = 12;
\r
65 const ATTR_STATEMENT_CLASS = 13;
\r
66 const ATTR_FETCH_TABLE_NAMES = 14;
\r
67 const ATTR_FETCH_CATALOG_NAMES = 15;
\r
68 const ATTR_DRIVER_NAME = 16;
\r
69 const ATTR_STRINGIFY_FETCHES = 17;
\r
70 const ATTR_MAX_COLUMN_LEN = 18;
\r
71 const ATTR_DEFAULT_FETCH_MODE = 19;
\r
72 const ATTR_EMULATE_PREPARES = 20;
\r
73 const ERRMODE_SILENT = 0;
\r
74 const ERRMODE_WARNING = 1;
\r
75 const ERRMODE_EXCEPTION = 2;
\r
76 const CASE_NATURAL = 0;
\r
77 const CASE_UPPER = 1;
\r
78 const CASE_LOWER = 2;
\r
79 const NULL_NATURAL = 0;
\r
80 const NULL_EMPTY_STRING = 1;
\r
81 const NULL_TO_STRING = 2;
\r
82 const FETCH_ORI_NEXT = 0;
\r
83 const FETCH_ORI_PRIOR = 1;
\r
84 const FETCH_ORI_FIRST = 2;
\r
85 const FETCH_ORI_LAST = 3;
\r
86 const FETCH_ORI_ABS = 4;
\r
87 const FETCH_ORI_REL = 5;
\r
88 const CURSOR_FWDONLY = 0;
\r
89 const CURSOR_SCROLL = 1;
\r
90 // from here orignal is undefined.
\r
91 const ERR_CANT_MAP = 0;
\r
92 const ERR_SYNTAX = 0;
\r
93 const ERR_CONSTRAINT = 0;
\r
94 const ERR_NOT_FOUND = 0;
\r
95 const ERR_ALREADY_EXISTS = 0;
\r
96 const ERR_NOT_IMPLEMENTED = 0;
\r
97 const ERR_MISMATCH = 0;
\r
98 const ERR_TRUNCATED = 0;
\r
99 const ERR_DISCONNECTED = 0;
\r
100 const ERR_NO_PERM = 0;
\r
102 const ERR_NONE = '00000';
\r
103 const PARAM_EVT_ALLOC = 0;
\r
104 const PARAM_EVT_FREE = 1;
\r
105 const PARAM_EVT_EXEC_PRE = 2;
\r
106 const PARAM_EVT_EXEC_POST = 3;
\r
107 const PARAM_EVT_FETCH_PRE = 4;
\r
108 const PARAM_EVT_FETCH_POST = 5;
\r
109 const PARAM_EVT_NORMALIZE = 6;
\r
111 const MYSQL_ATTR_INIT_COMMAND = 1002;
\r
115 * PDOException class of dummy
\r
117 class PDOException extends Exception
\r
122 * MysqlPDO class that wraps the mysql_ or mysqli_ function like PDO class
\r
126 // Prefix function name
\r
127 public static $handler;
\r
132 * Creates a PDO instance representing a connection to a MySQL database.
\r
133 * @param string $dsn DSN
\r
134 * @param string $username UserName
\r
135 * @param string $password Password
\r
136 * @param mixed $driver_options Options[optional]
\r
137 * @throws PDOException Thrown when failed to connect to the database.
\r
139 public function __construct($dsn, $username, $password, $driver_options = '')
\r
141 // select use function
\r
142 if ( function_exists('mysql_query') )
\r
144 MysqlPDO::$handler = 'mysql_';
\r
146 else if ( function_exists('mysqli_query') )
\r
148 MysqlPDO::$handler = 'mysqli_';
\r
152 throw new PDOException('Can not be found mysql_ or mysqli_ functions.', 'IM000');
\r
155 if ( preg_match('/host=([^;]+)/', $dsn, $matches) )
\r
157 $host = $matches[1];
\r
161 throw new PDOException('Host has not been set.', '01000');
\r
163 if ( preg_match('/port=([^;]+)/', $dsn, $matches) )
\r
165 $host .= ':' . $matches[1];
\r
169 $this->dbcon = @call_user_func(MysqlPDO::$handler . 'connect', $host, $username, $password);
\r
171 if ( $this->dbcon == FALSE )
\r
173 throw new PDOException('Failed to connect to the server.', '01000');
\r
177 if ( preg_match('/dbname=([^;]+)/', $dsn, $matches) )
\r
179 $dbname = $matches[1];
\r
182 if ( MysqlPDO::$handler == 'mysql_' )
\r
184 call_user_func(MysqlPDO::$handler . 'select_db', $dbname, $this->dbcon);
\r
188 call_user_func(MysqlPDO::$handler . 'select_db', $this->dbcon, $dbname);
\r
191 // set use character
\r
193 if ( is_array($driver_options) && array_key_exists(PDO::MYSQL_ATTR_INIT_COMMAND, $driver_options) )
\r
195 if ( preg_match('/SET\s+CHARACTER\s+SET\s+\'?([a-z0-9_-]+)\'?/', $driver_options[PDO::MYSQL_ATTR_INIT_COMMAND], $matches) )
\r
197 $charset = $matches[1];
\r
200 $server_info = call_user_func(MysqlPDO::$handler . 'get_server_info', $this->dbcon);
\r
201 $mysql_version = preg_replace('/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{1,2})(.*)$/', '$1.$2.$3', $server_info);
\r
203 if ( version_compare($mysql_version, '5.0.7', '>=') && function_exists(MysqlPDO::$handler . 'set_charset') )
\r
205 call_user_func(MysqlPDO::$handler . 'set_charset', $charset);
\r
207 else if ( version_compare($mysql_version, '5.0.7', '<') )
\r
209 $this->exec("SET CHARACTER SET '{$charset}';");
\r
213 $this->exec("SET NAMES '{$charset}';");
\r
220 * Close the connection to the MySQL server.
\r
222 public function __destruct()
\r
224 if ( $this->dbcon )
\r
226 @call_user_func(MysqlPDO::$handler . 'close', $this->dbcon);
\r
233 public function beginTransaction()
\r
241 public function commit()
\r
247 * Fetch the SQLSTATE associated with the last operation.
\r
248 * However, if successful '00000' Otherwise, the return to '01000'.
\r
249 * @return string Error code
\r
251 public function errorCode()
\r
253 $errno = call_user_func(MysqlPDO::$handler . 'errno', $this->dbcon);
\r
254 return $errno === 0 ? '00000' : '01000';
\r
258 * To get extended error information associated with the last operation.
\r
259 * Element 0: if successful '00000' Otherwise, the return to '01000'
\r
260 * Element 1: The return value of mysql_errno()
\r
261 * Element 2: The return value of mysql_error()
\r
262 * @return array Array of error information
\r
264 public function errorInfo()
\r
266 $errno = call_user_func(MysqlPDO::$handler . 'errno', $this->dbcon);
\r
267 $error = call_user_func(MysqlPDO::$handler . 'error', $this->dbcon);
\r
268 return array($errno === 0 ? '00000' : '01000', $errno, $error);
\r
271 public function exec($statement)
\r
273 $result = @call_user_func(MysqlPDO::$handler . 'query', $statement, $this->dbcon);
\r
274 if ( $result === TRUE )
\r
276 return @call_user_func(MysqlPDO::$handler . 'affected_rows', $this->dbcon);
\r
278 else if ( is_resource($result) )
\r
285 public function getAttribute($attribute)
\r
287 switch ( $attribute )
\r
289 case PDO::ATTR_SERVER_VERSION:
\r
290 return call_user_func(MysqlPDO::$handler . 'get_server_info', $this->dbcon);
\r
292 case PDO::ATTR_CLIENT_VERSION:
\r
293 return call_user_func(MysqlPDO::$handler . 'get_client_info');
\r
300 public static function getAvailableDrivers()
\r
302 return array('mysql');
\r
308 public function inTransaction()
\r
313 public function lastInsertId($name = null)
\r
315 return call_user_func(MysqlPDO::$handler . 'insert_id', $this->dbcon);
\r
321 public function prepare($statement, $driver_options = array())
\r
326 public function query($statement)
\r
328 $result = @call_user_func(MysqlPDO::$handler . 'query', $statement, $this->dbcon);
\r
329 return ($result == FALSE) ? FALSE : new MysqlPDOStatement($statement, $result, $this->dbcon);
\r
332 public function quote($string, $parameter_type = PDO::PARAM_STR)
\r
334 switch ( $parameter_type )
\r
336 case PDO::PARAM_NULL:
\r
338 case PDO::PARAM_BOOL:
\r
339 return $string ? '1' : '0';
\r
341 if ( $parameter_type == PDO::PARAM_INT && is_numeric($string) )
\r
347 return '\'' . call_user_func(MysqlPDO::$handler . 'real_escape_string', $string) . '\'';
\r
355 public function rollBack()
\r
363 public function setAttribute($attribute, $value)
\r
370 * MysqlPDOStatement class PDOStatement class like.
\r
372 class MysqlPDOStatement implements Iterator
\r
376 private $_queryString = '';
\r
378 private $def_fetch_mode = PDO::FETCH_BOTH;
\r
379 private $def_col_num = 0;
\r
380 private $def_class_name = 'stdClass';
\r
381 private $def_ctorargs = null;
\r
382 private $bind_object = null;
\r
384 public function __get($name)
\r
386 if ( $name == 'queryString' )
\r
388 return $this->_queryString;
\r
392 public function __construct($query, $result, $dbconnect = null)
\r
394 $this->dbcon = $dbconnect;
\r
395 $this->_queryString = $query;
\r
396 $this->result = $result;
\r
399 public function __destruct()
\r
401 $this->result = null;
\r
407 public function bindColumn($column, &$param, $type, $maxlen, $driverdata)
\r
415 public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length, $driver_options)
\r
423 public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
\r
428 public function closeCursor()
\r
430 return call_user_func(MysqlPDO::$handler . 'free_result', $this->result);
\r
433 public function columnCount()
\r
435 return call_user_func(MysqlPDO::$handler . 'num_fields', $this->result);
\r
441 public function debugDumpParams()
\r
446 public function errorCode()
\r
448 $errno = call_user_func(MysqlPDO::$handler . 'errno', $this->dbcon);
\r
449 return $errno === 0 ? '00000' : '01000';
\r
452 public function errorInfo()
\r
454 $errno = call_user_func(MysqlPDO::$handler . 'errno', $this->dbcon);
\r
455 $error = call_user_func(MysqlPDO::$handler . 'error', $this->dbcon);
\r
456 return array($errno === 0 ? '00000' : '01000', $errno, $error);
\r
462 public function execute($input_parameters)
\r
467 public function fetch($fetch_style = PDO::ATTR_DEFAULT_FETCH_MODE, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0)
\r
469 if ( !is_resource($this->result) || $cursor_orientation != PDO::FETCH_ORI_NEXT )
\r
474 if ( $fetch_style == PDO::ATTR_DEFAULT_FETCH_MODE )
\r
476 $fetch_style = $this->def_fetch_mode;
\r
479 switch ( $fetch_style )
\r
481 case PDO::FETCH_ASSOC:
\r
482 return @call_user_func(MysqlPDO::$handler . 'fetch_array', $this->result, MYSQL_ASSOC);
\r
483 case PDO::FETCH_BOTH:
\r
484 return @call_user_func(MysqlPDO::$handler . 'fetch_array', $this->result, MYSQL_BOTH);
\r
485 case PDO::FETCH_NUM:
\r
486 return @call_user_func(MysqlPDO::$handler . 'fetch_array', $this->result, MYSQL_NUM);
\r
487 case PDO::FETCH_OBJ:
\r
488 return $this->fetchObject();
\r
489 case PDO::FETCH_CLASS:
\r
490 return $this->fetchObject($this->def_class_name, $this->def_ctorargs);
\r
491 case PDO::FETCH_COLUMN:
\r
492 return $this->fetchColumn($this->def_col_num);
\r
493 case PDO::FETCH_BOUND:
\r
494 return FALSE; // Not supported
\r
495 case PDO::FETCH_INTO:
\r
496 return FALSE; // Not supported
\r
497 case PDO::FETCH_LAZY:
\r
498 return FALSE; // Not supported
\r
504 public function fetchAll($fetch_style = PDO::ATTR_DEFAULT_FETCH_MODE, $fetch_argument = null, $ctor_args = array())
\r
506 if ( $fetch_style == PDO::ATTR_DEFAULT_FETCH_MODE )
\r
508 $fetch_style = PDO::FETCH_BOTH;
\r
512 if ( ($fetch_style & PDO::FETCH_COLUMN) != 0 )
\r
514 if ( $fetch_style == PDO::FETCH_COLUMN )
\r
516 $column = $fetch_argument == null ? 0 : intval($fetch_argument);
\r
517 while ( $row = $this->fetchColumn($column) )
\r
522 elseif ( ($fetch_style & PDO::FETCH_UNIQUE) != 0 )
\r
526 elseif ( ($fetch_style & PDO::FETCH_GROUP) != 0 )
\r
531 elseif ( $fetch_style == PDO::FETCH_CLASS )
\r
533 while ( $row = $this->fetchObject($fetch_argument, $ctor_args) )
\r
538 elseif ( $fetch_style == PDO::FETCH_FUNC )
\r
540 while ( $row = $this->fetch(PDO::FETCH_ASSOC) )
\r
542 $ret[] = call_user_func_array($fetch_argument, array_values($row));
\r
547 while ( $row = $this->fetch($fetch_style) )
\r
555 public function fetchColumn($column_number = 0)
\r
557 if ( $ret = $this->fetch(PDO::FETCH_NUM) )
\r
559 return $ret[$column_number];
\r
564 public function fetchObject($class_name = 'stdClass', $ctor_args = null)
\r
566 if ( is_array($ctor_args) && !empty($ctor_args) )
\r
568 return @call_user_func(MysqlPDO::$handler . 'fetch_object', $this->result, $class_name, $ctor_args);
\r
572 return @call_user_func(MysqlPDO::$handler . 'fetch_object', $this->result, $class_name);
\r
576 public function getAttribute($attribute)
\r
578 switch ( $attribute )
\r
588 public function getColumnMeta($column)
\r
591 if ( MysqlPDO::$handler == 'mysql_' )
\r
593 $result['name'] = @call_user_func(MysqlPDO::$handler . 'field_name', $this->result, $column);
\r
601 public function nextRowset()
\r
606 public function rowCount()
\r
608 return @call_user_func(MysqlPDO::$handler . 'affected_rows', $this->dbcon);
\r
614 public function setAttribute($attribute, $value)
\r
619 public function setFetchMode($mode, &$mode_argument, $ctorargs)
\r
623 case PDO::FETCH_COLUMN:
\r
624 $this->def_col_num = $mode_argument;
\r
626 case PDO::FETCH_CLASS:
\r
627 $this->def_class_name = $mode_argument;
\r
628 $this->def_ctorargs = $ctorargs;
\r
630 case PDO::FETCH_INTO:
\r
631 $this->bind_object = &$mode_argument;
\r
632 return FALSE; // Not supported
\r
634 $this->def_fetch_mode = $mode;
\r
641 private $iterator_value;
\r
651 return ($this->iterator_value = $this->fetch());
\r
656 return $this->iterator_value;
\r
667 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
668 * Copyright (C) 2012 The Nucleus Group
670 * This program is free software; you can redistribute it and/or
671 * modify it under the terms of the GNU General Public License
672 * as published by the Free Software Foundation; either version 2
673 * of the License, or (at your option) any later version.
674 * (see nucleus/documentation/index.html#license for more info)
677 * @license http://nucleuscms.org/license.txt GNU General Public License
678 * @copyright Copyright (C) 2012 The Nucleus Group
682 if ( !class_exists('PDO') )
685 * Dummy constant of the PDO class
689 /* constant values */
690 const PARAM_NULL = 0;
694 const PARAM_STMT = 4;
695 const PARAM_BOOL = 5;
696 const PARAM_INPUT_OUTPUT = 128; // orignal is undefined.
697 const FETCH_LAZY = 1;
698 const FETCH_ASSOC = 2;
700 const FETCH_BOTH = 4;
702 const FETCH_BOUND = 6;
703 const FETCH_COLUMN = 7;
704 const FETCH_CLASS = 8;
705 const FETCH_INTO = 9;
706 const FETCH_FUNC = 10;
707 const FETCH_NAMED = 11;
708 const FETCH_KEY_PAIR = 12;
709 const FETCH_GROUP = 65536;
710 const FETCH_UNIQUE = 196608;
711 const FETCH_CLASSTYPE = 262144;
712 const FETCH_SERIALIZE = 524288;
713 const FETCH_PROPS_LATE = 1048576;
714 const ATTR_AUTOCOMMIT = 0;
715 const ATTR_PREFETCH = 1;
716 const ATTR_TIMEOUT = 2;
717 const ATTR_ERRMODE = 3;
718 const ATTR_SERVER_VERSION = 4;
719 const ATTR_CLIENT_VERSION = 5;
720 const ATTR_SERVER_INFO = 6;
721 const ATTR_CONNECTION_STATUS = 7;
723 const ATTR_CURSOR_NAME = 9;
724 const ATTR_CURSOR = 10;
725 const ATTR_ORACLE_NULLS = 11;
726 const ATTR_PERSISTENT = 12;
727 const ATTR_STATEMENT_CLASS = 13;
728 const ATTR_FETCH_TABLE_NAMES = 14;
729 const ATTR_FETCH_CATALOG_NAMES = 15;
730 const ATTR_DRIVER_NAME = 16;
731 const ATTR_STRINGIFY_FETCHES = 17;
732 const ATTR_MAX_COLUMN_LEN = 18;
733 const ATTR_DEFAULT_FETCH_MODE = 19;
734 const ATTR_EMULATE_PREPARES = 20;
735 const ERRMODE_SILENT = 0;
736 const ERRMODE_WARNING = 1;
737 const ERRMODE_EXCEPTION = 2;
738 const CASE_NATURAL = 0;
739 const CASE_UPPER = 1;
740 const CASE_LOWER = 2;
741 const NULL_NATURAL = 0;
742 const NULL_EMPTY_STRING = 1;
743 const NULL_TO_STRING = 2;
744 const FETCH_ORI_NEXT = 0;
745 const FETCH_ORI_PRIOR = 1;
746 const FETCH_ORI_FIRST = 2;
747 const FETCH_ORI_LAST = 3;
748 const FETCH_ORI_ABS = 4;
749 const FETCH_ORI_REL = 5;
750 const CURSOR_FWDONLY = 0;
751 const CURSOR_SCROLL = 1;
752 // from here orignal is undefined.
753 const ERR_CANT_MAP = 0;
754 const ERR_SYNTAX = 0;
755 const ERR_CONSTRAINT = 0;
756 const ERR_NOT_FOUND = 0;
757 const ERR_ALREADY_EXISTS = 0;
758 const ERR_NOT_IMPLEMENTED = 0;
759 const ERR_MISMATCH = 0;
760 const ERR_TRUNCATED = 0;
761 const ERR_DISCONNECTED = 0;
762 const ERR_NO_PERM = 0;
764 const ERR_NONE = '00000';
765 const PARAM_EVT_ALLOC = 0;
766 const PARAM_EVT_FREE = 1;
767 const PARAM_EVT_EXEC_PRE = 2;
768 const PARAM_EVT_EXEC_POST = 3;
769 const PARAM_EVT_FETCH_PRE = 4;
770 const PARAM_EVT_FETCH_POST = 5;
771 const PARAM_EVT_NORMALIZE = 6;
773 const MYSQL_ATTR_INIT_COMMAND = 1002;
777 * PDOException class of dummy
779 class PDOException extends Exception
784 * MysqlPDO class that wraps the mysql_ or mysqli_ function like PDO class
788 // Prefix function name
789 public static $handler;
794 * Creates a PDO instance representing a connection to a MySQL database.
795 * @param string $dsn DSN
796 * @param string $username UserName
797 * @param string $password Password
798 * @param mixed $driver_options Options[optional]
799 * @throws PDOException Thrown when failed to connect to the database.
801 public function __construct($dsn, $username, $password, $driver_options = '')
803 // select use function
804 if ( function_exists('mysql_query') )
806 MysqlPDO::$handler = 'mysql_';
808 else if ( function_exists('mysqli_query') )
810 MysqlPDO::$handler = 'mysqli_';
814 throw new PDOException('Can not be found mysql_ or mysqli_ functions.', 'IM000');
817 if ( preg_match('/host=([^;]+)/', $dsn, $matches) )
823 throw new PDOException('Host has not been set.', '01000');
825 if ( preg_match('/port=([^;]+)/', $dsn, $matches) )
827 $host .= ':' . $matches[1];
831 $this->dbcon = @call_user_func(MysqlPDO::$handler . 'connect', $host, $username, $password);
833 if ( $this->dbcon == FALSE )
835 throw new PDOException('Failed to connect to the server.', '01000');
839 if ( preg_match('/dbname=([^;]+)/', $dsn, $matches) )
841 $dbname = $matches[1];
844 if ( MysqlPDO::$handler == 'mysql_' )
846 call_user_func(MysqlPDO::$handler . 'select_db', $dbname, $this->dbcon);
850 call_user_func(MysqlPDO::$handler . 'select_db', $this->dbcon, $dbname);
855 if ( is_array($driver_options) && array_key_exists(PDO::MYSQL_ATTR_INIT_COMMAND, $driver_options) )
857 if ( preg_match('/SET\s+CHARACTER\s+SET\s+\'?([a-z0-9_-]+)\'?/', $driver_options[PDO::MYSQL_ATTR_INIT_COMMAND], $matches) )
859 $charset = $matches[1];
862 $server_info = call_user_func(MysqlPDO::$handler . 'get_server_info', $this->dbcon);
863 $mysql_version = preg_replace('/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{1,2})(.*)$/', '$1.$2.$3', $server_info);
865 if ( version_compare($mysql_version, '5.0.7', '>=') && function_exists(MysqlPDO::$handler . 'set_charset') )
867 call_user_func(MysqlPDO::$handler . 'set_charset', $charset);
869 else if ( version_compare($mysql_version, '5.0.7', '<') )
871 $this->exec("SET CHARACTER SET '{$charset}';");
875 $this->exec("SET NAMES '{$charset}';");
882 * Close the connection to the MySQL server.
884 public function __destruct()
888 @call_user_func(MysqlPDO::$handler . 'close', $this->dbcon);
895 public function beginTransaction()
903 public function commit()
909 * Fetch the SQLSTATE associated with the last operation.
910 * However, if successful '00000' Otherwise, the return to '01000'.
911 * @return string Error code
913 public function errorCode()
915 $errno = call_user_func(MysqlPDO::$handler . 'errno', $this->dbcon);
916 return $errno === 0 ? '00000' : '01000';
920 * To get extended error information associated with the last operation.
921 * Element 0: if successful '00000' Otherwise, the return to '01000'
922 * Element 1: The return value of mysql_errno()
923 * Element 2: The return value of mysql_error()
924 * @return array Array of error information
926 public function errorInfo()
928 $errno = call_user_func(MysqlPDO::$handler . 'errno', $this->dbcon);
929 $error = call_user_func(MysqlPDO::$handler . 'error', $this->dbcon);
930 return array($errno === 0 ? '00000' : '01000', $errno, $error);
933 public function exec($statement)
935 $result = @call_user_func(MysqlPDO::$handler . 'query', $statement, $this->dbcon);
936 if ( $result === TRUE )
938 return @call_user_func(MysqlPDO::$handler . 'affected_rows', $this->dbcon);
940 else if ( is_resource($result) )
947 public function getAttribute($attribute)
949 switch ( $attribute )
951 case PDO::ATTR_SERVER_VERSION:
952 return call_user_func(MysqlPDO::$handler . 'get_server_info', $this->dbcon);
954 case PDO::ATTR_CLIENT_VERSION:
955 return call_user_func(MysqlPDO::$handler . 'get_client_info');
962 public static function getAvailableDrivers()
964 return array('mysql');
970 public function inTransaction()
975 public function lastInsertId($name = null)
977 return call_user_func(MysqlPDO::$handler . 'insert_id', $this->dbcon);
983 public function prepare($statement, $driver_options = array())
988 public function query($statement)
990 $result = @call_user_func(MysqlPDO::$handler . 'query', $statement, $this->dbcon);
991 return ($result == FALSE) ? FALSE : new MysqlPDOStatement($statement, $result, $this->dbcon);
994 public function quote($string, $parameter_type = PDO::PARAM_STR)
996 switch ( $parameter_type )
998 case PDO::PARAM_NULL:
1000 case PDO::PARAM_BOOL:
1001 return $string ? '1' : '0';
1003 if ( $parameter_type == PDO::PARAM_INT && is_numeric($string) )
1009 return '\'' . call_user_func(MysqlPDO::$handler . 'real_escape_string', $string) . '\'';
1017 public function rollBack()
1025 public function setAttribute($attribute, $value)
1032 * MysqlPDOStatement class PDOStatement class like.
1034 class MysqlPDOStatement implements Iterator
1038 private $_queryString = '';
1040 private $def_fetch_mode = PDO::FETCH_BOTH;
1041 private $def_col_num = 0;
1042 private $def_class_name = 'stdClass';
1043 private $def_ctorargs = null;
1044 private $bind_object = null;
1046 public function __get($name)
1048 if ( $name == 'queryString' )
1050 return $this->_queryString;
1054 public function __construct($query, $result, $dbconnect = null)
1056 $this->dbcon = $dbconnect;
1057 $this->_queryString = $query;
1058 $this->result = $result;
1061 public function __destruct()
1063 $this->result = null;
1069 public function bindColumn($column, &$param, $type, $maxlen, $driverdata)
1077 public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length, $driver_options)
1085 public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
1090 public function closeCursor()
1092 return call_user_func(MysqlPDO::$handler . 'free_result', $this->result);
1095 public function columnCount()
1097 return call_user_func(MysqlPDO::$handler . 'num_fields', $this->result);
1103 public function debugDumpParams()
1108 public function errorCode()
1110 $errno = call_user_func(MysqlPDO::$handler . 'errno', $this->dbcon);
1111 return $errno === 0 ? '00000' : '01000';
1114 public function errorInfo()
1116 $errno = call_user_func(MysqlPDO::$handler . 'errno', $this->dbcon);
1117 $error = call_user_func(MysqlPDO::$handler . 'error', $this->dbcon);
1118 return array($errno === 0 ? '00000' : '01000', $errno, $error);
1124 public function execute($input_parameters)
1129 public function fetch($fetch_style = PDO::ATTR_DEFAULT_FETCH_MODE, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0)
1131 if ( !is_resource($this->result) || $cursor_orientation != PDO::FETCH_ORI_NEXT )
1136 if ( $fetch_style == PDO::ATTR_DEFAULT_FETCH_MODE )
1138 $fetch_style = $this->def_fetch_mode;
1141 switch ( $fetch_style )
1143 case PDO::FETCH_ASSOC:
1144 return @call_user_func(MysqlPDO::$handler . 'fetch_array', $this->result, MYSQL_ASSOC);
1145 case PDO::FETCH_BOTH:
1146 return @call_user_func(MysqlPDO::$handler . 'fetch_array', $this->result, MYSQL_BOTH);
1147 case PDO::FETCH_NUM:
1148 return @call_user_func(MysqlPDO::$handler . 'fetch_array', $this->result, MYSQL_NUM);
1149 case PDO::FETCH_OBJ:
1150 return $this->fetchObject();
1151 case PDO::FETCH_CLASS:
1152 return $this->fetchObject($this->def_class_name, $this->def_ctorargs);
1153 case PDO::FETCH_COLUMN:
1154 return $this->fetchColumn($this->def_col_num);
1155 case PDO::FETCH_BOUND:
1156 return FALSE; // Not supported
1157 case PDO::FETCH_INTO:
1158 return FALSE; // Not supported
1159 case PDO::FETCH_LAZY:
1160 return FALSE; // Not supported
1166 public function fetchAll($fetch_style = PDO::ATTR_DEFAULT_FETCH_MODE, $fetch_argument = null, $ctor_args = array())
1168 if ( $fetch_style == PDO::ATTR_DEFAULT_FETCH_MODE )
1170 $fetch_style = PDO::FETCH_BOTH;
1174 if ( ($fetch_style & PDO::FETCH_COLUMN) != 0 )
1176 if ( $fetch_style == PDO::FETCH_COLUMN )
1178 $column = $fetch_argument == null ? 0 : intval($fetch_argument);
1179 while ( $row = $this->fetchColumn($column) )
1184 elseif ( ($fetch_style & PDO::FETCH_UNIQUE) != 0 )
1188 elseif ( ($fetch_style & PDO::FETCH_GROUP) != 0 )
1193 elseif ( $fetch_style == PDO::FETCH_CLASS )
1195 while ( $row = $this->fetchObject($fetch_argument, $ctor_args) )
1200 elseif ( $fetch_style == PDO::FETCH_FUNC )
1202 while ( $row = $this->fetch(PDO::FETCH_ASSOC) )
1204 $ret[] = call_user_func_array($fetch_argument, array_values($row));
1209 while ( $row = $this->fetch($fetch_style) )
1217 public function fetchColumn($column_number = 0)
1219 if ( $ret = $this->fetch(PDO::FETCH_NUM) )
1221 return $ret[$column_number];
1226 public function fetchObject($class_name = 'stdClass', $ctor_args = null)
1228 if ( is_array($ctor_args) && !empty($ctor_args) )
1230 return @call_user_func(MysqlPDO::$handler . 'fetch_object', $this->result, $class_name, $ctor_args);
1234 return @call_user_func(MysqlPDO::$handler . 'fetch_object', $this->result, $class_name);
1238 public function getAttribute($attribute)
1240 switch ( $attribute )
1250 public function getColumnMeta($column)
1253 if ( MysqlPDO::$handler == 'mysql_' )
1255 $result['name'] = @call_user_func(MysqlPDO::$handler . 'field_name', $this->result, $column);
1263 public function nextRowset()
1268 public function rowCount()
1270 return @call_user_func(MysqlPDO::$handler . 'affected_rows', $this->dbcon);
1276 public function setAttribute($attribute, $value)
1281 public function setFetchMode($mode, &$mode_argument, $ctorargs)
1285 case PDO::FETCH_COLUMN:
1286 $this->def_col_num = $mode_argument;
1288 case PDO::FETCH_CLASS:
1289 $this->def_class_name = $mode_argument;
1290 $this->def_ctorargs = $ctorargs;
1292 case PDO::FETCH_INTO:
1293 $this->bind_object = &$mode_argument;
1294 return FALSE; // Not supported
1296 $this->def_fetch_mode = $mode;
1303 private $iterator_value;
1313 return ($this->iterator_value = $this->fetch());
1318 return $this->iterator_value;
1326 >>>>>>> skinnable-master