jeudi 7 mai 2015

PDO SQLite Cannot Open Database

I do alright with PHP in Linux environments, but I'm working on a PHP application that uses PDO's sqlite on IIS 8 on Windows Server 2012 R2.

Reading from the database works fine; attempting to insert or update results in the rather unhelpful error, "unable to open database file"

Code that works fine:

if (!($db = new PDO('sqlite:assets/database.db'))) { ?>
    ...
} else {
    $stmt="SELECT
             ... ";

    $stmt = $db->prepare($stmt);

    $stmt->execute(array(":person" => $this->uid));
}

Code that doesn't work:

if (!($db = new PDO('sqlite:assets/database.db'))) { ?>
    ...
} else {
    $stmt = "INSERT INTO bills(date, label, categ, amount, timestamp) VALUES(?, ?, ?, ?, ?)";

    $stmt = $db->prepare($stmt);
    var_dump($stmt->errorInfo()); 
    // yields : array(3) { [0]=> string(0) "" [1]=> NULL [2]=> NULL }

    $stmt->execute([$fData['date'], $fData['label'], $fData['categ'], $fData['amount'], $fData['timestamp']]);
    var_dump($stmt->errorInfo()); 
    // yields : array(3) { [0]=> string(5) "HY000" [1]=> int(14) [2]=> string(28) "unable to open database file" }
}

Things I've tried already:

  • Making sure the IIS user has read/write permissions of the database file, per this question
  • Making sure the IIS user has read/write permissions of the directory containing the database file. per this question
  • Check IIS error logs for any indication of what's going on. (The only thing present is an unrelated warning caused by this request failing.)
  • Making sure it works with another Database (it works fine with mySQL, but sqlite is a hard requirement for the final application.)

Any help greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire