-1

After going through a few tutorials of displaying data to php from python and my sqlite database, I keep getting this error and don't know how to fix it. I'm in need of urgent help.

Error Message Execption: could not find driver

This is my code:

<HTML>
<HEAD>
<TITLE>Sensor Data Log</TITLE>
</HEAD> 
<BODY>
<?php
try {
     $db = new PDO('sqlite:/var/www/ledDB.sq3');
     $db->exec(
        "CREATE TABLE IF NOT EXISTS sensor (Id INTEGER PRIMARY KEY, ID INTEGER, Sensor TEXT, Log DATETIME)");
     $db->exec(
       "INSERT INTO sensor (ID, Sensor, Log) VALUES ('1', 'Red Sensor', 2014/07/02 19:19);".
       "INSERT INTO sensor (ID, Sensor, Log) VALUES ('1', 'Red Sensor', 2014/07/02 19:20);".
       "INSERT INTO sensor (ID, Sensor, Log) VALUES ('1', 'Red Sensor', 2014/07/02 19:21);");

     $table = "<tr><th>Id</th><th>ID</th><th>Sensor</th><th>log</th></tr>";
     $result = $db->query('SELECT * FROM sensor');

     foreach ($result as $row) {
        $table .=
            "<tr><td>" . $row['Id'] . "</td>" . 
            "<td>" . $row['ID'] . "</td>" .
            "<td>" . $row['Sensor'] . "</td>" .
            "<td>" . $row['Log'] . "</td></tr>";}

      print "<table border=1> $table </table>";
      $db = NULL;}
catch(PDOException $e) {
    print "Exception : " . $e->getMessage();}?></BODY></HTMl>

Hope you guys could help out with it as soon as possible, thanks in advance, guys.

  • I see no relevance to the Raspberry Pi. – joan Jul 3 '14 at 7:38
  • I'm using Raspberry Pi as hardware side, joan. – user3127380 Jul 3 '14 at 8:07
1

While PHP's PDO itself extension is provided by the php5 package, not all of its database-specific drivers are. You'll have to install the PDO sqlite driver separately:

sudo apt-get install php5-sqlite
  • Wow, it works, Another Code. Thanks alot, Another Code. – user3127380 Jul 3 '14 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.