user3973427
user3973427

Reputation: 1435

PHP error message: Fatal error: Call to a member function bindParam() on a non-object

I moved our database from MySQL to SQLite.

I now get an error message:

Fatal error: Call to a member function bindParam() on a non-object in C:\inetpub\wwwroot\calendar\insert.php on line 9

Here is the script:

<?php
session_start();

$dbh = new PDO('sqlite:database.sqlite');

$stmt = $dbh->prepare("INSERT INTO events (fn, sn, bn, sd, ed) VALUES (:fn, :sn, :bn, STR_TO_DATE(:dp1,'%Y-%m-%d'), DATE_ADD(STR_TO_DATE(:dp2,'%Y-%m-%d'), INTERVAL 1 DAY))");

foreach ($_POST as $key => $value) {
    $stmt->bindParam("$key", $_POST[$key]);
}

$stmt->execute();

header("Location: /");
?>

I guess it is something relating to SQLite since I didn't get this error message on MySQL.

Can someone help?

Upvotes: 1

Views: 154

Answers (1)

Hanky Panky
Hanky Panky

Reputation: 46900

STR_TO_DATE(:dp1,'%Y-%m-%d'), DATE_ADD(STR_TO_DATE(:dp2,'%Y-%m-%d'), INTERVAL 1 DAY)

SQLLite does not provide the date functions you have used in your query, hence your prepare call fails which causes the error on the next line.

Upvotes: 1

Related Questions