php sqlite_query函数的例子

发布时间:2019-10-03编辑:脚本学堂
本文分享php中使用sqlite_query函数的例子,共三个例子,学习下sqlite_query函数的用法,有需要的朋友可以作个参考。

本节内容:
php sqlite_query函数实例。

例1,sqlite_query函数的例子
 

复制代码 代码示例:
<?php
/**
* sqlite_query函数简单示例
* by www.jb200.com
*/
    $sqldb = sqlite_open("mydatabase.db");
    $results = sqlite_query($sqldb, "SELECT * FROM employee");
    while (list($empid, $name) = sqlite_fetch_array($results)) {
        echo "Name: $name (Employee ID: $empid) <br />";
    }
    sqlite_close($sqldb);
?>

例2,使用sqlite查询()函数
 

复制代码 代码示例:

<?php
     $db = sqlite_open(":memory:");
     if(!$db) die("Could not create the temporary database");

     $query = "CREATE TABLE cities(name VARCHAR(255), state VARCHAR(2))";
     sqlite_query($db, $query);
     $cities[] = array('name' => 'Chicago','state'=> 'IL');
     foreach($cities as $city) {
         $query = "INSERT INTO cities VALUES(" ."'{$city['name']}', '{$city['state']}')";
         if(!sqlite_query($db, $query)) {
          trigger_error("Could not insert city " . "'{$city['name']}, {$city['state']}");
         }
     }
     sqlite_close($db);
?>

例3,sqlite_query查询测试
 

复制代码 代码示例:

<?php
/**
* sqlite_query查询的测试用例
* by www.jb200.com
*/
$dbconn = sqlite_open('phpdb');

    if ($dbconn) {
            script!
            sqlite_query($dbconn, "INSERT INTO animal VALUES('a', 14)");
            sqlite_query($dbconn, "INSERT INTO animal VALUES('b', 16)");
            sqlite_query($dbconn, "INSERT INTO animal VALUES('c', 13)");
            var_dump(sqlite_array_query($dbconn, "SELECT * FROM animal", SQLITE_ASSOC));
    } else {
            print "Connection to database failed!n";
    }
 ?>