As of PHP 5.4 support for Sqlite2 has been removed. I have a large web app that was built with sqlite2 as the database backend and thus it exploded when I updated PHP. If you're in a similar situation I've written a few wrapper functions that will allow your app to work whilst you convert the code to sqlite3.
Firstly convert your DB to an sqlite3 db.
sqlite OLD.DB .dump | sqlite3 NEW.DB
Then add the following functions to your app:
<?php
function sqlite_open($location,$mode)
{
$handle = new SQLite3($location);
return $handle;
}
function sqlite_query($dbhandle,$query)
{
$array['dbhandle'] = $dbhandle;
$array['query'] = $query;
$result = $dbhandle->query($query);
return $result;
}
function sqlite_fetch_array(&$result,$type)
{
#Get Columns
$i = 0;
while ($result->columnName($i))
{
$columns[ ] = $result->columnName($i);
$i++;
}
$resx = $result->fetchArray(SQLITE3_ASSOC);
return $resx;
}
?>
They're not perfect by any stretch but they seem to be working ok as a temporary measure while I convert the site.
Hope that helps someone
SQLite3
- 導入
- インストール/設定
- 定義済み定数
- SQLite3 — SQLite3 クラス
- SQLite3::busyTimeout — 接続がビジー状態のときのハンドラを設定する
- SQLite3::changes — 直近の SQL 文で変更 (あるいは挿入、削除) された行の数を返す
- SQLite3::close — データベースとの接続を閉じる
- SQLite3::__construct — SQLite3 オブジェクトを作成し、SQLite 3 データベースをオープンする
- SQLite3::createAggregate — SQL の集約関数として使用する PHP 関数を登録する
- SQLite3::createFunction — SQL のスカラー関数として使用する PHP 関数を登録する
- SQLite3::escapeString — 適切にエスケープされた文字列を返す
- SQLite3::exec — 指定したデータベースに、結果を返さないクエリを実行する
- SQLite3::lastErrorCode — 直近で失敗した SQLite リクエストの結果コードを数値で返す
- SQLite3::lastErrorMsg — 直近で失敗した SQLite リクエストについての英文テキストの説明を返す
- SQLite3::lastInsertRowID — 直近の INSERT 文でデータベースに追加された行の ID を返す
- SQLite3::loadExtension — SQLite 拡張ライブラリを読み込む
- SQLite3::open — SQLite データベースをオープンする
- SQLite3::prepare — 実行する SQL 文を準備する
- SQLite3::query — SQL クエリを実行する
- SQLite3::querySingle — クエリを実行し、単一の結果を返す
- SQLite3::version — SQLite3 ライブラリのバージョンを、文字列定数と数値で返す
- SQLite3Stmt — SQLite3Stmt クラス
- SQLite3Stmt::bindParam — パラメータを変数にバインドする
- SQLite3Stmt::bindValue — パラメータの値を変数にバインドする
- SQLite3Stmt::clear — 現在バインドされているすべてのパラメータをクリアする
- SQLite3Stmt::close — プリペアドステートメントを閉じる
- SQLite3Stmt::execute — プリペアドステートメントを実行し、結果セットオブジェクトを返す
- SQLite3Stmt::paramCount — プリペアドステートメント内のパラメータの数を返す
- SQLite3Stmt::reset — プリペアドステートメントをリセットする
- SQLite3Result — SQLite3Result クラス
- SQLite3Result::columnName — n 番目のカラムの名前を返す
- SQLite3Result::columnType — n 番目のカラムの型を返す
- SQLite3Result::fetchArray — 結果の行を、連想配列あるいは数値添字配列あるいはその両方で取得する
- SQLite3Result::finalize — 結果セットを閉じる
- SQLite3Result::numColumns — 結果セットのカラム数を返す
- SQLite3Result::reset — 結果セットを最初の行に戻す
Anonymous ¶
1 year ago
Anonymous ¶
2 years ago
If you get the following error for non-encrypted databases:
Warning: SQLite3::query() [sqlite3.query]: Unable to prepare statement: 26, file is encrypted or is not a database in …
... use PDO instead of this library.
alan at chandlerfamily dot org dot uk ¶
2 years ago
PHP 5.3.3 introduced sqlite3::busyTimeout(int milliseconds) which does not currently seem to be documented.
It believe it acts like sqlite::busyTimeout - that is it tells sqlite3 to call an internal busyHandler if SQLITE_BUSY is returned from any call which waits a short period and then retries. It continues to do this until milliseconds milliseconds have elapsed and then returns the SQLITE_BUSY status.
I don't know whether the default 60 second value is in place if this function is not called.
