使用sqlite的时候出现问题,无法读出数据,支持sqlite3的环境可以正常

class MyDB extends SQLite3
{
    function __construct()
    {
  $db = "/path/to/data.db";
        $this->open($db);
    }
}

$db = new MyDB();
// $db->exec('CREATE TABLE foo (bar STRING)');
// $db->exec("INSERT INTO foo (bar) VALUES ('This is a test')");

$result = $db->query('SELECT * FROM table');
var_dump($result->fetch());


sqlite函数的不行,提示“file is encrypted or is not a database”

if ($db = sqlite_open($db, 0666, $sqliteerror)) {
    // sqlite_query($db, 'CREATE TABLE foo (bar varchar(10))');
    // sqlite_query($db, "INSERT INTO foo VALUES ('fnord')");
    $result = sqlite_query($db, 'select bar from foo');
    var_dump(sqlite_fetch_array($result));
} else {
    die($sqliteerror);
}





If you get an error message:
Warning: sqlite_open() [function.sqlite-open]: file is encrypted or is not a database
then most probably your code is accessing a SQLite3 database.
sqlite_open() only supports SQLite2.  Use PDO to access SQLite3.

sqlite_open()只支持sqlite2版本,暂不支持sqlite3版本;
若连接sqlite3必须用sqlite_pdo去连接,参考下面的代码:

$dbh = new PDO('sqlite:whl.db');
if ($dbh){
echo 'OK';
}else{
echo 'Err';
}
$res = $dbh->query('insert into info(info_name) values("whlll");');
{
if(!$res) die("bad");
}
echo "good";


http://hi.baidu.com/xiaowu...


原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
发表评论
AD
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐