XSDatabaseSQLite
包 | XS.util.db |
---|---|
继承关系 | class XSDatabaseSQLite » XSDatabase |
版本 | 1.0.0 |
源代码 | sdk/php/util/XSDataSource.class.php |
使用传统的 SQLite 扩展
Public 方法
名称 | 描述 | 定义于 |
---|---|---|
close() | 关闭数据库 | XSDatabaseSQLite |
connect() | 打开数据库 | XSDatabaseSQLite |
query() | 执行 SQL 语句查询 | XSDatabaseSQLite |
query1() | 查询数据库首行 | XSDatabase |
setUtf8() | 设置数据库字符集为 UTF-8 | XSDatabase |
方法明细
close()
方法
public void close()
|
源码: sdk/php/util/XSDataSource.class.php#L643 (显示)
public function close()
{
if ($this->link)
{
sqlite_close($this->link);
$this->link = null;
}
}
关闭数据库
connect()
方法
public void connect(array $param)
| ||
$param | array | 连接参数, 包含: path |
源码: sdk/php/util/XSDataSource.class.php#L634 (显示)
public function connect($param)
{
if (($this->link = sqlite_open($param['path'])) === false)
throw new XSException("Can not open sqlite file: '{$param['path']}'");
}
打开数据库
query()
方法
public mixed query(string $sql)
| ||
$sql | string | 要执行的 SQL 语句 |
{return} | mixed |
源码: sdk/php/util/XSDataSource.class.php#L657 (显示)
public function query($sql)
{
//echo "[DEBUG] SQL: $sql\n";
$res = sqlite_query($this->link, $sql);
if ($res === false)
throw new XSException('SQLITE ERROR: ' . sqlite_error_string($this->link));
if (!is_resource($res))
$ret = $res;
else
{
$ret = array();
while ($tmp = sqlite_fetch_array($res, SQLITE_ASSOC))
{
$ret[] = $tmp;
}
}
return $ret;
}
执行 SQL 语句查询