如何使用PHP连接到SQLite数据库?

前端之家收集整理的这篇文章主要介绍了如何使用PHP连接到SQLite数据库?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个sqlite数据库,我试图用 PHP连接到它.这是我使用的:
<?PHP
    $dbconn = sqlite_open('combadd.sqlite');

    if ($dbconn) {
        $result = sqlite_query($dbconn,"SELECT * FROM combo_calcs WHERE options='easy'");
        var_dump(sqlite_fetch_array($result,sqlITE_ASSOC));
    } else {
        print "Connection to database Failed!\n";
    }
?>

但是,我得到这个错误

Warning: sqlite_open() [function.sqlite-open]: file is encrypted or is not a database in C:\xampp\htdocs\deepthi\combadd\combadd_db.PHP on line 4
Connection to database Failed!

怎么了,怎么解决

尝试使用PDO而不是sqlite_open:
$dir = 'sqlite:/[YOUR-PATH]/combadd.sqlite';
$dbh  = new PDO($dir) or die("cannot open the database");
$query =  "SELECT * FROM combo_calcs WHERE options='easy'";
foreach ($dbh->query($query) as $row)
{
    echo $row[0];
}
原文链接:https://www.f2er.com/php/131986.html

猜你在找的PHP相关文章