* Support write into SQLite by dao.

This commit is contained in:
liuyongkai
2023-06-11 07:26:36 +00:00
parent ca91f89102
commit e0b6facd98
2 changed files with 120 additions and 5 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
class sqlite
{
public $app;
/**
* 全局对象$sqlite
* The global sqlite object.
*
* @var object
* @access public
*/
public $dbh = null;
public function __construct()
{
global $app;
$this->app = $app;
}
/**
* 连接sqlite数据库。
* Connect to sqlite database.
*
* @param string $sqliteFile
* @access public
* @return object
*/
public function connectSqlite(string $sqliteFile = ''): PDO
{
$tmpRoot = $this->app->getTmpRoot();
if(empty($sqliteFile) || !is_file($sqliteFile)) $sqliteFile = $tmpRoot . 'sqlite.db';
$sqliteFile = realpath($sqliteFile);
if(strpos($sqliteFile, $tmpRoot) !== 0) helper::end("The sqlite file '$sqliteFile' is not in the tmp root '$tmpRoot'");
$dbh = new PDO("sqlite:$sqliteFile");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->dbh = $dbh;
return $dbh;
}
public function exec($sql = '')
{
$this->dbh->exec($sql);
}
public function processSQL(string $sql): string
{
return $sql;
}
}