如何使用PHP连接sqlite数据库? [英] how to connect a sqlite database using PHP?

查看:118
本文介绍了如何使用PHP连接sqlite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了很多使用PHP PDO连接数据库的方法.我有很多样本,我不确定是什么问题.

i have tried lot to connect database using PHP PDO. i have got lot of samples, i am not sure what was problem.

下面是我的代码

<?php
    try
    {
        // $db = new PDO('sqlite:sampleDB.db3');
        // $db = new SQLiteDatabase('sampleDB.sqlite', 0666, $error);  
        $db = new PDO('sqlite:sampleDB.sqlite');
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
?>

我尝试了很多方法来打开连接.请告诉我正确的方法...

i have tried lot of way to open a connection. please tell me the correct way...

推荐答案

出于相同的原因,我放弃了PDO驱动程序,而改用sqlite3模块.

I gave up with PDO driver, and used sqlite3 module instead for same reasons.

使用sqlite3模块:

With sqlite3 module:

class DB extends SQLite3
{
        function __construct( $file )
        {
            $this->open( $file );
        }
}

$db = new DB( 'sampleDB.sqlite' );

我知道这不是解决您问题的方法,但是如果没有其他效果,那可能会有用.

I know it's not a solution for your problem, but if nothing else works, this could be useful.

这篇关于如何使用PHP连接sqlite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆