SQLite查询无法从其他PHP文件中运行
I have strange issue. When I am running file Database/connectDatabase.php:
<?php
$db = new PDO('sqlite:database.db') or die("fail to connect db");
$qry = $db->prepare("SELECT * FROM user WHERE name=? AND pass=?");
$qry->execute(array("a", "a")) or die;
it's working. But if I use it in file LoginSystem/registration.php:
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/Database/connectDatabase.php');
it's thrownig: "Fatal error: Call to a member function execute() on boolean in .../Database/connectDatabase.php on line 4"
我有一个奇怪的问题。 当我运行文件Database / connectDatabase.php时: p>
&lt;?php
$ db = new PDO('sqlite:database.db')或die(“fail” 连接db“);
$ qry = $ db-&gt; prepare(”SELECT * FROM user WHERE name =?AND pass =?“);
$ qry-&gt; execute(array(”a“,” 一个“))或死;
code> pre>
它正在工作。
但是如果我在文件LoginSystem / registration.php中使用它: p>
define('__ ROOT__',dirname(dirname(__ FILE __)));
require_once(__ ROOT __。'/ Database / connectDatabase.php');
code> pre>
它是thrownig:“致命错误:在第4行的... / Database / connectDatabase.php中的布尔值上调用成员函数execute()” p>
div>
I managed to find out solution. I was using local path to database ('sqlite:database.db'). PHP probably is pasting code from require - when file with require is in other catalogue code is not working.