123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
-
-
-
- require_once('PDOStatement_mysql.class.php');
-
-
- class PDO_mysql {
-
-
-
- var $__connection;
- var $__dbinfo;
- var $__persistent = false;
- var $__errorCode = '';
- var $__errorInfo = Array('');
-
-
-
- function PDO_mysql(&$host, &$db, &$user, &$pass) {
- if(!@$this->__connection = &mysql_connect($host, $user, $pass))
- $this->__setErrors('DBCON');
- else {
- if(!@mysql_select_db($db, $this->__connection))
- $this->__setErrors('DBER');
- else
- $this->__dbinfo = Array($host, $user, $pass, $db);
- }
- }
-
-
-
- function close() {
- $result = is_resource($this->__connection);
- if($result) {
- mysql_close($this->__connection);
- }
- return $result;
- }
-
-
-
- function errorCode() {
- return $this->__errorCode;
- }
-
-
-
- function errorInfo() {
- return $this->__errorInfo;
- }
-
-
-
- function exec($query) {
- $result = 0;
- if(!is_null($this->__uquery($query)))
- $result = mysql_affected_rows($this->__connection);
- if(is_null($result))
- $result = false;
- return $result;
- }
-
-
-
- function lastInsertId() {
- $id = mysql_insert_id($this->__connection);
- if ($id > 0) {
- return $id;
- } else {
- $query = $this->prepare('SELECT last_insert_id()');
- $query->execute();
- return $query->fetchColumn();
- }
- }
-
-
-
- function prepare($query, $array = Array()) {
- return new PDOStatement_mysql($query, $this->__connection, $this->__dbinfo);
- }
-
-
-
- function query($query) {
- $query = @mysql_unbuffered_query($query, $this->__connection);
- if($query) {
- $result = Array();
- while($r = mysql_fetch_assoc($query))
- array_push($result, $r);
- }
- else {
- $result = false;
- $this->__setErrors('SQLER');
- }
- return $result;
- }
-
-
-
- function quote($string) {
- return ('"'.mysql_escape_string($string).'"');
- }
-
-
-
-
-
- function getAttribute($attribute) {
- $result = false;
- switch($attribute) {
- case PDO_ATTR_SERVER_INFO:
- $result = mysql_get_host_info($this->__connection);
- break;
- case PDO_ATTR_SERVER_VERSION:
- $result = mysql_get_server_info($this->__connection);
- break;
- case PDO_ATTR_CLIENT_VERSION:
- $result = mysql_get_client_info();
- break;
- case PDO_ATTR_PERSISTENT:
- $result = $this->__persistent;
- break;
- }
- return $result;
- }
-
-
-
- function setAttribute($attribute, $mixed) {
- $result = false;
- if($attribute === PDO_ATTR_PERSISTENT && $mixed != $this->__persistent) {
- $result = true;
- $this->__persistent = (boolean) $mixed;
- mysql_close($this->__connection);
- if($this->__persistent === true)
- $this->__connection = &mysql_pconnect($this->__dbinfo[0], $this->__dbinfo[1], $this->__dbinfo[2]);
- else
- $this->__connection = &mysql_connect($this->__dbinfo[0], $this->__dbinfo[1], $this->__dbinfo[2]);
- mysql_select_db($this->__dbinfo[3], $this->__connection);
- }
- return $result;
- }
-
-
-
- function beginTransaction() {
- return false;
- }
-
- function commit() {
- return false;
- }
-
- function rollBack() {
- return false;
- }
-
-
-
- function __setErrors($er) {
- if(!is_resource($this->__connection)) {
- $errno = mysql_errno();
- $errst = mysql_error();
- }
- else {
- $errno = mysql_errno($this->__connection);
- $errst = mysql_error($this->__connection);
- }
- $this->__errorCode = &$er;
- $this->__errorInfo = Array($this->__errorCode, $errno, $errst);
- }
-
- function __uquery(&$query) {
- if(!@$query = mysql_query($query, $this->__connection)) {
- $this->__setErrors('SQLER');
- $query = null;
- }
- return $query;
- }
- }
- ?>
|