0

I want to insert data to my database stored in SQLite but, when I pass my query to pdo prepare it's retruns false and giving me this message: Fatal error: Uncaught Error: Call to a member function execute() on boolean.

Here is My PHP code:

$ql = "INSERT INTO customer_in (`ledger_id`, `daybook_id`, `description`, `amount`, `date`) VALUES (31, 141, '', 5000, '07/02/2018')";

try {
      $con = new Connection();
      $conn = $con->connect();
      $conn->exec("SET NAMES utf8");
      $stmt = $conn->prepare($q1);
      $results = $stmt->execute();
    }catch (PDOException $e) {
      // this is rolback fanction
      $conn->rollback();
      echo "query is not exe";
    }
Baqi Aman
  • 23
  • 1
  • 7

1 Answers1

1

It's because $conn->prepare($q1); returned FALSE. The problem is that you've named the query string as $ql instead of $q1, and then you called $q1 in the code below it.

This code should work:

$q1 = "INSERT INTO customer_in (`ledger_id`, `daybook_id`, `description`, `amount`, `date`) VALUES (31, 141, '', 5000, '07/02/2018')";

try {
      $con = new Connection();
      $conn = $con->connect();
      $conn->exec("SET NAMES utf8");
      $stmt = $conn->prepare($q1);
      $results = $stmt->execute();
    }catch (PDOException $e) {
      // this is rolback fanction
      $conn->rollback();
      echo "query is not exe";
    }
Ketan Malhotra
  • 1,255
  • 3
  • 16
  • 44
  • Thanks, I've tried and changed the name of my variable, but still it's not working and showing same error: Fatal error: Uncaught Error: Call to a member function execute() on boolean. – Baqi Aman Jul 08 '18 at 10:02