Original code for non registrered users: <?php
if (!defined('SMF'))
die('Hacking attempt...');
if(!defined('SQLITE_NUM')) define ( 'SQLITE_NUM' , SQLITE3_NUM);
// Included by default from php 5.3.x
if(phpversion() < '5.3.0') return;
if(!class_exists("SQLite3")) return;
if(!function_exists('sqlite_open')) {
function sqlite_open($location,$mode,$error) {
// Error and Mode not used
$dB = new SQLite3($location);
return $dB;
}
}
if(!function_exists('sqlite_popen')) {
function sqlite_popen($location,$mode,$error) {
// Error and Mode not used
$dB = new SQLite3($location);
return $dB;
}
}
if(!function_exists('sqlite_query')) {
function sqlite_query($query, $dB , $result = FALSE , &$errmsg = FALSE ) {
global $db_name;
$created = FALSE;
if(!is_object($dB)) {
if (substr($db_name, -3) != '.db')
$db_name .= '.db';
$dB = new SQLite3($db_name);
$created = TRUE;
}
if(stristr($query,'SELECT') /*|| stristr($query,'INSERT') || stristr($query,'UPDATE') */) {
$result = $dB->query($query);
} else {
$result = $dB->exec($query);
}
if($created === TRUE)
$dB->close();
if($result === FALSE)
return FALSE;
return $result;
}
}
if(!function_exists('sqlite_fetch_array')) {
function sqlite_fetch_array(&$result,$type = SQLITE3_BOTH ) {
if(!is_object($result)) {
return $result;
}
$resx = $result->fetchArray( $type );
return $resx;
}
}
if(!function_exists('sqlite_create_function')) {
function sqlite_create_function ( $dB , $funcname , $callback , $args = '-1' ) {
$ret = $dB->createFunction ( $funcname , $callback , $args);
return $ret;
}
}
if(!function_exists('sqlite_escape_string')) {
function sqlite_escape_string ( $query ) {
global $db_connection , $db_name;
$created = FALSE;
if(!is_object($db_connection)) {
if (substr($db_name, -3) != '.db')
$db_name .= '.db';
$dB = new SQLite3($db_name);
$created = TRUE;
} else {
$dB = $db_connection;
}
$esql = $dB->escapeString($query);
if($created === TRUE)
$dB->close();
return $esql;
}
}
if(!function_exists('sqlite_changes')) {
function sqlite_changes () {
global $db_connection , $db_name;
$created = FALSE;
if(!is_object($db_connection)) {
if (substr($db_name, -3) != '.db')
$db_name .= '.db';
$dB = new SQLite3($db_name);
$created = TRUE;
} else {
$dB = $db_connection;
}
$changes = $dB->changes();
if($created === TRUE)
$dB->close();
return $changes;
}
}
if(!function_exists('sqlite_num_rows')) {
function sqlite_num_rows ( $result ) {
$numRows = 0;
while ($result->fetchArray())
$numRows ++;
return ($numRows);
}
}
if(!function_exists('sqlite_libversion')) {
function sqlite_libversion () {
global $db_connection , $db_name;
$created = FALSE;
if(!is_object($db_connection)) {
if (substr($db_name, -3) != '.db')
$db_name .= '.db';
$dB = new SQLite3($db_name);
$created = TRUE;
} else {
$dB = $db_connection;
}
$version = $dB->version();
if($created === TRUE)
$dB->close();
return $version;
}
}
if(!function_exists('sqlite_last_insert_rowid' )) {
function sqlite_last_insert_rowid ( $dB ) {
return $dB->lastInsertRowID();
}
}
if(!function_exists('sqlite_last_error')) {
function sqlite_last_error ( $dB ) {
global $db_name;
$created = FALSE;
if(!is_object($dB)) {
if (substr($db_name, -3) != '.db')
$db_name .= '.db';
$dB = new SQLite3($db_name);
$created = TRUE;
}
$errCode = $dB->lastErrorCode();
if($created === TRUE)
$dB->close();
return $errCode;
}
}
if(!function_exists('sqlite_error_string')) {
function sqlite_error_string ($errno) {
global $db_connection , $db_name;
$created = FALSE;
if(!is_object($db_connection)) {
if (substr($db_name, -3) != '.db')
$db_name .= '.db';
$dB = new SQLite3($db_name);
$created = TRUE;
} else {
$dB = $db_connection;
}
$lastError = $dB->lastErrorMsg();
if($created === TRUE)
$dB->close();
return $lastError;
}
}
?>