gpt4 book ai didi

php - 新的 PDO 拒绝工作

转载 作者:可可西里 更新时间:2023-10-31 22:41:35 25 4
gpt4 key购买 nike

我想用这些行创建一个 sqlite 数据库:

<?php
echo "here<br/>";

try {
$db_connection = new PDO('sqlite:file.db');
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}

echo "there<br/>";
?>

在那之后我期待输出

here
there

和文件夹中存在的文件 file.db

但是我只看到这里,没有文件。所以看起来 new 甚至没有抛出异常就失败了。

这是我目前检查的内容:

  • php版本为5.4.16
  • 文件夹对apache是​​可写的(其实权限是777)

还有什么可能/是什么问题?

编辑

我还尝试了以下 felipsmartins 的回答:

$ php -i | grep -i sqlite
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/sqlite3.ini,
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
PDO drivers => sqlite
pdo_sqlite
PDO Driver for SQLite 3.x => enabled
SQLite Library => 3.7.17
sqlite3
SQLite3 support => enabled
SQLite3 module version => 0.7
SQLite Library => 3.7.17
sqlite3.extension_dir => no value => no value

但是 phpinfo() 不显示任何 PDOsqlite 条目。

最佳答案

如 PHP 中指定的 documentaion , PDO 需要 DSN 字符串上的绝对路径名:

To access a database on disk, append the absolute path to the DSN prefix.

$pdo = new PDO('sqlite:' . __DIR__ . DIRECTORY_SEPARATOR . 'file.db');

当然,还要确保启用了 SQLite 支持。查看快速命令:php -i | grep -i sqlite

enter image description here

关于php - 新的 PDO 拒绝工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33790293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com