I have Apache web server installed on Manjaro(Sway) linux, and default location of projects is:
/srv/http/
I have created a folder for my project by the name test in the location and have created a database named db1.db inside it through terminal using the following steps (followed this article):
sqlite3 db1
sqlite> create table tblone(one varchar(10), two smallint);
sqlite> insert into tblone values('helloworld',20);
sqlite> insert into tblone values('linux', 30);
I can verify that the table has been created successfully by running the following command:
sqlite> select * from tblone;
which outputs:
helloworld|20
linux|30
I need to create a PHP file which connects the above created database using PDO.
So, inside test folder, I create a file index.php with the following content:
<?php
$myPDO = new PDO('sqlite:test/db1.db');
$result = $myPDO->query("SELECT * FROM tblone");
foreach($result as $row){
echo $row['one']. "\n";
}
?>
But I get a blank white screen in output, when I enter http://localhost/test/index.php in browser. Where am I going wrong?
'sqlite:db1.db'.db1.dbonly, but that didn't help. The web server log file states this:[Wed Oct 09 01:11:57.508603 2024] [php:error] [pid 4497:tid 4497] [client ::1:42034] PHP Fatal error: Uncaught PDOException: could not find driver in /srv/http/test/index.php:2\nStack trace:\n#0 /srv/http/test/index.php(2): PDO->__construct()\n#1 {main}\n thrown in /srv/http/test/index.php on line 2. But I am not able to understand it? What should I do? Can you help?php -mfrom the command line, you'll get a list of installed modules, which should includepdo_sqlitebut probably doesn't. Not familiar at all with Manjaro/Sway so can't help in regards to how you'd install that. It might be as simple as uncommenting (or adding) the lineextension=pdo_sqlite.soin yourphp.inifile.Uncaught PDOException: SQLSTATE[HY000] [14] unable to open database file ...new PDO('sqlite:/srv/http/test/db1.db')(or whatever it is) and maybechmod go+rit if needed.