diff options
-rw-r--r-- | it_dbi.class | 54 | ||||
-rw-r--r-- | it_user.class | 2 |
2 files changed, 28 insertions, 28 deletions
diff --git a/it_dbi.class b/it_dbi.class index 3d4f2a9..b2f3717 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -37,7 +37,7 @@ class it_dbi 'classprefix' => "", 'getfieldinfo' => true, # do not read schema. only select() allowed 'localized_defaultlanguage' => "de", # Localize fields with this suffix, e.g. copy title_de to title on read - 'unbuffered' => false, # use mysql_unbuffered_query (WARNING this is not at all equivalent to normal it_dbi WARNING) + 'unbuffered' => false, # use MYSQLI_USE_RESULT (WARNING this is not at all equivalent to normal it_dbi WARNING) ); var $_key; # Key of currently loaded record or null (public readonly) @@ -116,7 +116,7 @@ function createclasses($p = array()) if (!$tables = $state['tables']) { - for ($tables = array(), $res = $dbi->query('SHOW TABLES', $p); $row = mysql_fetch_row($res);) + for ($tables = array(), $res = $dbi->query('SHOW TABLES', $p); $row = mysqli_fetch_row($res);) $tables[] = $row[0]; $state = it_dbi::_state_get($dbid); # State could have been modified by query above @@ -154,7 +154,7 @@ function createclass($p) if (!($tables = $state['tables'])) { - for ($tables = array(), $res = $dbi->query('SHOW TABLES', $p); $row = mysql_fetch_row($res);) + for ($tables = array(), $res = $dbi->query('SHOW TABLES', $p); $row = mysqli_fetch_row($res);) $tables[] = $row[0]; $state = it_dbi::_state_get($dbid); # State could have been modified by query above @@ -207,27 +207,27 @@ function _connect($p = array()) { # Force new link if same server/user was seen before (mysql ignores selected db) if ($GLOBALS['it_dbi']->_connected["{$p['server']}/{$p['user']}"]++) - $this->_link = @mysql_connect($p['server'], $p['user'], $p['pw'], true); + $this->_link = @mysqli_connect($p['server'], $p['user'], $p['pw']); else - $this->_link = @mysql_connect($p['server'], $p['user'], $p['pw']); + $this->_link = @mysqli_connect($p['server'], $p['user'], $p['pw']); if (!$this->_link) { # One retry after a short delay - it::log('sqllog', "it_dbi(): retrying DB link (mysql_connect {$p['server']}, {$p['db']}): " . mysql_error()); + it::log('sqllog', "it_dbi(): retrying DB link (mysqli_connect {$p['server']}, {$p['db']}): " . mysqli_error()); sleep(1); - $this->_link = @mysql_connect($p['server'], $p['user'], $p['pw'], true); + $this->_link = @mysqli_connect($p['server'], $p['user'], $p['pw']); } if (!$this->_link) - $this->_fatal("_connect(): can't create DB link (mysql_connect {$p['user']}@{$p['server']}, {$p['db']})"); + $this->_fatal("_connect(): can't create DB link (mysqli_connect {$p['user']}@{$p['server']}, {$p['db']})"); - if (!(@mysql_select_db($p['db'], $this->_link))) + if (!(@mysqli_select_db($this->_link, $p['db']))) $this->_fatal("_connect(): can't select database \"{$p['db']}\""); # set charset used for this connection if ($p['charset']) - if (!mysql_set_charset($p['charset'], $this->_link)) + if (!mysqli_set_charset($this->_link, $p['charset'])) $this->_fatal("_connect(): can't set charset \"{$p['charset']}\""); # NOTE: This overwrites old state but that is on purpose. New link means we should refetch all info about connection @@ -391,10 +391,10 @@ function _fatal($text) { $text = get_class($this).'::'.$text; - if ($this->_link && ($errstr = mysql_error($this->_link))) - $text = "\"$errstr\" in $text [errno " . mysql_errno($this->_link) . "]"; + if ($this->_link && ($errstr = mysqli_error($this->_link))) + $text = "\"$errstr\" in $text [errno " . mysqli_errno($this->_link) . "]"; - if ($this->_link && ($res = @mysql_fetch_row(mysql_query('select database()', $this->_link)))) # dont create extra errs + if ($this->_link && ($res = @mysqli_fetch_row(mysqli_query($this->_link, 'select database()')))) # dont create extra errs $text .= ", DB: " . $res[0]; it::fatal($text . ", Server: " . $this->_p['server']); @@ -456,17 +456,17 @@ function query($query, $p = array()) debug("{$p['user']}@{$p['server']}:{$p['db']}" . '.' . get_class($this) . "::query(\"$query\")", 4); - if (!($result = ($p['unbuffered'] ? mysql_unbuffered_query($query, $this->_link) : mysql_query($query, $this->_link))) && $p['safety']) + if (!($result = mysqli_query($this->_link, $query, $p['unbuffered'] ? MYSQLI_USE_RESULT : MYSQLI_STORE_RESULT)) && $p['safety']) { - $errno = mysql_errno($this->_link); + $errno = mysqli_errno($this->_link); if (($p['safety'] < 2) && ($errno == 1062)) # Duplicate entry return false; if ($errno == 2006) # mysql server has gone away: retry { - it::log('sqllog', "it_dbi(): reconnecting mysql_connect {$p['server']}, {$p['db']}"); + it::log('sqllog', "it_dbi(): reconnecting mysqli_connect {$p['server']}, {$p['db']}"); $this->_connect(array('reconnect' => true)); - $result = $p['unbuffered'] ? mysql_unbuffered_query($query, $this->_link) : mysql_query($query, $this->_link); + $result = mysqli_query($this->_link, $query, $p['unbuffered'] ? MYSQLI_USE_RESULT : MYSQLI_STORE_RESULT); } if (!$result) @@ -569,11 +569,11 @@ function select(/* $query = array|string, ... */) $this->clear(false); if ($this->_result = $this->query($sql = "SELECT $what FROM $join " . $this->_where($query, $this->_link))) { - $result = mysql_num_rows($this->_result); + $result = mysqli_num_rows($this->_result); if ($calc_found_rows) { - list($count) = mysql_fetch_row($this->query('SELECT FOUND_ROWS()')); + list($count) = mysqli_fetch_row($this->query('SELECT FOUND_ROWS()')); $this->_found_rows = intval($count); } @@ -596,7 +596,7 @@ function iterate() { if (!$this->_nofetch) { - if ($this->_data = mysql_fetch_assoc($this->_result)) + if ($this->_data = mysqli_fetch_assoc($this->_result)) { if ($localizedfields = $this->_localizedfields) foreach ($localizedfields as $field => $dummy) @@ -661,7 +661,7 @@ function insert($tags = array(), $command = "INSERT") if ($result = $this->query("$command INTO {$this->_p['table']} " . $set)) { - $id = ($this->_p['autoincrement'] && !isset($tags[$this->_p['keyfield']])) ? mysql_insert_id($this->_link) : $tags[$this->_p['keyfield']]; + $id = ($this->_p['autoincrement'] && !isset($tags[$this->_p['keyfield']])) ? mysqli_insert_id($this->_link) : $tags[$this->_p['keyfield']]; if ($this->_p['keyfield'] && !$this->read($id) && $this->_p['safety']) $this->_fatal("insert(): can't read record back (key truncated?), id=\"$id\""); } @@ -717,7 +717,7 @@ function update($tags = array(), $where = null) if ($result = $this->query("UPDATE {$this->_p['table']} $set " . $this->_where($where, $this->_link))) { - $result = mysql_affected_rows($this->_link); + $result = mysqli_affected_rows($this->_link); if (array_key_exists($this->_p['keyfield'], $tags)) # Did we just update the key? $this->_key = $tags[$this->_p['keyfield']]; @@ -749,7 +749,7 @@ function delete($query = null) } if ($query && $this->query("DELETE FROM {$this->_p['table']} " . $this->_where($query, $this->_link))) - $result = mysql_affected_rows($this->_link); + $result = mysqli_affected_rows($this->_link); return $result; } @@ -763,7 +763,7 @@ function delete($query = null) function escape_string($str) { $this->_connect(); - return "'" . mysql_real_escape_string($str, $this->_link) . "'"; + return "'" . mysqli_real_escape_string($this->_link, $str) . "'"; } @@ -780,7 +780,7 @@ function _get_field_info() if (!($this->_fields = $state['fields'][$this->_p['table']])) { debug("it_dbi(): no fields for {$dbid}.{$this->_p['table']}, calculating.", 5); - for ($res = $this->query('SHOW COLUMNS FROM ' . $this->_p['table']); $res && ($field = mysql_fetch_assoc($res)); ) + for ($res = $this->query('SHOW COLUMNS FROM ' . $this->_p['table']); $res && ($field = mysqli_fetch_assoc($res)); ) { $this->_fields[$field['Field']] = $field + array('Length' => preg_match('/date|time/', $field['Type']) ? 20 : intval(it::match('\d+', $field['Type']))); if (preg_match('/^(tiny|small|medium|)int|^float|^double/', $field['Type'])) @@ -865,8 +865,8 @@ function rewind() $this->select(); # Only rewind if not already at start and results present - if (!$this->_nofetch && mysql_num_rows($this->_result)) - mysql_data_seek($this->_result, 0); + if (!$this->_nofetch && mysqli_num_rows($this->_result)) + mysqli_data_seek($this->_result, 0); $this->_iteratorkey = 0; $this->iterate(); diff --git a/it_user.class b/it_user.class index 75fc52e..ccbcfc2 100644 --- a/it_user.class +++ b/it_user.class @@ -353,7 +353,7 @@ function create_password($length = 8, $charset = 'abcdefghjkpqrstuvwxyz23456789A function crypt_password($password) { $result = $this->query("SELECT PASSWORD(" . $this->escape_string($password) . ")"); - list($pw) = mysql_fetch_array($result); + list($pw) = mysqli_fetch_array($result); return $pw; } |