当前位置:数据库 > SQLite >>

SQLite研究之phpSQLiteAdmin

QLiteManager虽然强大,但是对环境还是有一些要求,同时程序也过于庞大(2M?)

有一个替换的方案:phpSQLiteAdmin

目前版本是0.2,只有不到100K。配置部署也非常简单,放到Web的目录里面就可以了。

答案:


下面是一些实例代码,最常用的几种方法。分别实现: 执行非查询SQL,返回全部查询,逐条返回查询。

echo "
PDO
"
;try { $conn = new PDO('sqlite2:jimmy.sqlite'); $string = 'working...
'
;echo $conn->quote($string);echo 'PDO Connection Ok','
'
; $conn->beginTransaction(); $conn->exec("INSERT INTO test values(null,'pdo','pdo_test...')"); echo $conn->commit();echo 'A Transaction: Insert Data ok','
'
; } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } echo 'get all data','
'
;$query=$conn->query('SELECT * FROM test'); $result=$query->fetchAll();trace( $result); echo 'get data line by line', '
n'
;$query = $conn->prepare("SELECT * FROM test where id > ?");if ($query->execute(array('1'))) {while ($row = $query->fetch()) {trace($row);}}

PDO模式下注意,官方资料new PDO('sqlite:xxx');
有误,要声明为:$conn = new PDO('sqlite2:jimmy.sqlite') 才能工作。

echo "
SQLite
"
;$db = new SQLiteDatabase('jimmy2');$db->query("INSERT INTO test VALUES(null,'sqlite','sqlite class')");echo 'get data all','
'
;$result = $db->arrayQuery('SELECT * FROM test LIMIT 25', SQLITE_ASSOC);foreach ($result as $entry) {echo 'title: ' . $entry['title'] . ' content: ' . $entry['content'];}echo '
get data line by line'
,'
'
;$result = $db->query("SELECT * FROM test LIMIT 25");while($row=$result->fetch()){print_r($row);}

echo "
Zend
"
;require_once 'Zend.php';Zend::loadClass('Zend_Db');$params = array ('dbname' => 'jimmy.sqlite','sqlite2' => TRUE);$db = Zend_Db::factory('PDO_SQLITE', $params);try { $db->beginTransaction();$db->query("INSERT INTO test VALUES(null,'sqlite','zend sqlite')"); echo "
Insert OK "
.$db->lastInsertId();; $db->commit();} catch (Exception $e) { $db->rollBack(); echo $e->getMessage();}$result = $db->fetchAll("SELECT * FROM test");trace(</SP

上一个:SQLite编译安装步骤
下一个:利用VB手把手教你制作简易mp3播放器

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,