This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
class SQL {
private
$sql_connection,
$schema_version,
$sql_tables,
$last_query,
$last_insert_id;
//creates new connection
public function __construct($server, $user, $password, $database) {
//warn if MySQL extension is not installed
if(!extension_loaded('mysql'))
throw new LibraryMissingException('MySQL library is not installed. Database access is impossible.', 0);
//establish a link to MySQL
$con = @mysql_connect($server,$user,$password);
if ($con === false)
throw new DatabaseConnectException('Unable to connect to mysql server. Please make sure it is up and running and you have correct user/password in config.inc.php.', 1);
//select otserv database
if (!mysql_select_db($database))
throw new DatabaseSelectException('Unable to select database: '.$database.'. Make sure it exists.', 2);
//retrieve table list
$result = mysql_query('SHOW TABLES');
if ($result === false)
DatabaseQueryException('Failed to retrieve a table list.');
while ($a = mysql_fetch_array($result))
$this->sql_tables[] = $a[0];
//retrieve schema version
$result = mysql_query('SELECT value FROM schema_info WHERE name = \'version\'');
throw new DatabaseException('Notice: AutoSetup has attempted to create missing tables for you. Please create MySQL tables manually from "database.sql" if you are still getting this message.', 3);
}elseif (!$is_server_db) {
throw new DatabaseException('It appears you don\'t have SQL sample imported for OT server or it is not supported.', 4);
}elseif ($is_cvs && !$is_svn) {
throw new DatabaseException('This AAC version does not support your server. Consider using SQL v1.5.', 5);
}
return true;
}
public function repairTables() {
if (isset($this->sql_tables))
foreach($this->sql_tables as $table)
mysql_query('REPAIR TABLE '.$table);
return true;
}
######################################
# Methods for simple data access #
######################################
//Insert data
public function myInsert($table,$data) {global $cfg;
$fields = array_keys($data);
$values = array_values($data);
$query = 'INSERT INTO `'.mysql_escape_string($table).'` (';
foreach ($fields as $field)
$query.= '`'.mysql_escape_string($field).'`,';
$query = substr($query, 0, strlen($query)-1);
$query.= ') VALUES (';
foreach ($values as $value)
if ($value === null)
$query.= 'NULL,';
else
$query.= $this->quote($value).',';
$query = substr($query, 0, strlen($query)-1);
$query.= ');';
$this->myQuery($query);
return true;
}
//Replace data
public function myReplace($table,$data) {global $cfg;
$fields = array_keys($data);
$values = array_values($data);
$query = 'REPLACE INTO `'.mysql_escape_string($table).'` (';
foreach ($fields as $field)
$query.= '`'.mysql_escape_string($field).'`,';
$query = substr($query, 0, strlen($query)-1);
$query.= ') VALUES (';
foreach ($values as $value)
if ($value === null)
$query.= 'NULL,';
else
$query.= $this->quote($value).',';
$query = substr($query, 0, strlen($query)-1);
$query.= ');';
$this->myQuery($query);
return true;
}
//Retrieve single row
public function myRetrieve($table,$data) {
$fields = array_keys($data);
$values = array_values($data);
$query = 'SELECT * FROM `'.mysql_escape_string($table).'` WHERE (';
for ($i = 0; $i < count($fields); $i++)
$query.= '`'.mysql_escape_string($fields[$i]).'` = '.$this->quote($values[$i]).' AND ';
$query = substr($query, 0, strlen($query)-4);
$query.=');';
$this->myQuery($query);
if ($this->num_rows() != 1) return false;
return $this->fetch_array();
}
//Update data
public function myUpdate($table,$data,$where,$limit=1) {
$fields = array_keys($data);
$values = array_values($data);
$query = 'UPDATE `'.mysql_escape_string($table).'` SET ';
info
Grupo: Artesão
Registrado: 19/05/11
Posts: 109
Reputação: +4
sql.php:
Erro:
Fatal error: Uncaught exception 'DatabaseQueryException'
Message: Error #1048:Column 'ip' cannot be null
SQL query: INSERT INTO `nicaw_account_logs` (id, ip, account_id, date, action) VALUES(NULL, INET_ATON('::1'), 6, UNIX_TIMESTAMP(NOW()), 'Created')
File: sql.php on line: 94
Script was terminated because something unexpected happened. You can report this, if you think it's a bug.
Debug Backtrace:Disabled
Ajdem-Me