无法使用php访问SQLite3数据库

我花了很多时间试图让本地网络服务器正常工作(我是新手)</ p >

我在www文件夹中创建了一个sqlite3数据库('database.sql'),并尝试用许多不同的php命令(php 5.5,我检查过)调用它,例如'$ test = new SQLite( 'database.sql')'或与SQLite3相同,都没有运气。 还尝试了$ test-&gt; open('database.sql')。
总是出现致命错误“Class'SQLite'not found”。 我已经花了太多时间来确定这是一个非常简单的问题,我很抱歉不得不问这个问题!</ p>
</ div>

展开原文

原文

I've spent many-a hour trying to get a local webserver working (I'm new)

I created a sqlite3 database ('database.sql') in the www folder, and tried calling it with numerous different php commands (php 5.5, I checked) such as '$test = new SQLite('database.sql')' or the same with SQLite3, both with no luck. Also tried $test->open('database.sql'). Always with the fatal error "Class 'SQLite' not found". I've spent too many hours on what I'm sure is a very simple problem, I'm sorry to have to ask this!

dongshang1529
dongshang1529 列出您尝试过的所有命令以及发生的事情。这将有助于回答者。
大约 6 年之前 回复

3个回答



要使用PHP5和SQLite打开数据库,我们需要使用PDO而不是sqlite_open()函数。</ p>

这是打开或创建数据库的方法:(不确定它是否没有错误)</ p>

 尝试{
/ ***连接到SQLite数据库* ** /
$ dbh =新PDO(“sqlite:VPN0.sqlite”);
echo“句柄已创建......&lt; br&gt;”;
}

catch(PDOException $ e){
echo $ e-&gt; getMessage();
echo“&lt; br&gt;数据库加载UNSUCCESSFULLY ..”;
die(“&lt; br&gt;查询已关闭$ error”);
}

echo“数据库已加载SUCCESSFULLY ....”;
</ code> </ pre>

希望这会有所帮助!</ p>
</ div>

展开原文

原文

To open a DB using PHP5 and SQLite we need to use a PDO and not the sqlite_open() function.

This is how to open or create a database: (not sure if it's bug free)

try {
    /*** connect to SQLite database ***/
    $dbh = new PDO("sqlite:VPN0.sqlite");
    echo "Handle has been created ...... <br>";
}

catch(PDOException $e) {
    echo $e->getMessage();
    echo "<br>Database is loaded UNSUCCESSFULLY .. ";
    die("<br>Query is closed $error");
}

echo "Database loaded SUCCESSFULLY ....";

Hope this helps!

dsfasdfsda234234
dsfasdfsda234234 您需要安装PDO(php数据对象)。 这是链接:php.net/manual/en/pdo.installation.php
大约 6 年之前 回复
dsuvs66406
dsuvs66406 “装载不成功”,说“找不到驱动程序”和“未定义变量”
大约 6 年之前 回复



你可以使用一个名为sqlite3的php包(以及上面给出的PDO)。 以下是使用它的一小部分代码。</ p>

  $ db = new SQLite3(DATABASE); 
if(isset($ dbversion)){//只有较新的版本 聊天将有这个
$ version = $ db-&gt; querySingle(“SELECT value FROM parameters WHERE name ='db_version'”);
</ code> </ pre>

DATABASE 变量已定义为</ p>

  define('DATA_DIR',$ datadir);  //应该在网络空间之外
define('DATABASE',DATA_DIR.'chat.db');
</ code> </ pre>
</ div>

展开原文

原文

There is a php package called sqlite3 which you can use (as well as PDO which is given above). Here is a fraction of code which uses it.

            $db = new SQLite3(DATABASE);
        if (isset($dbversion)) { //only newer versions of chat will have this
            $version = $db->querySingle("SELECT value FROM parameters WHERE name = 'db_version'");

Where the DATABASE variable has been defined with

define('DATA_DIR',$datadir);  //Should be outside of web space
define('DATABASE',DATA_DIR.'chat.db');



您确定服务器上已安装该软件包吗?</ p>

如果您还在 有问题你可以做几件事。 首先,在页面中使用 phpinfo(); </ code>来确定是否安装了SQLite3扩展。</ p>

其次,如果要使用PDO,请确保以下内容 你的php.ini中的行是未注释的:</ p>

  extension = php_pdo_sqlite.dll 
</ code> </ pre>

如果你有 要取消注释,您需要重新启动服务器才能使更改生效。</ p>
</ div>

展开原文

原文

Are you sure that the package is installed on your server?

If you're still having problems you can do a couple of things. First, use phpinfo(); in a page to determine if the SQLite3 extension is installed.

Second, if you want to use PDO make sure that the following line in your php.ini is un-commented:

extension=php_pdo_sqlite.dll

If you have to un-comment this you will need to restart your server for the changes to take effect.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐