mercredi 23 septembre 2015

PHP SQLite3 Insert and select last ID not returning result

I'm trying to insert new data to SQLite db and select the last ID, when I'm executing the statement in SQLite browser I see that the statement is correct and I get the result. But when I'm trying to get the result in my PHP script, I get "null".

<?php

class SQLiteDb extends SQLite3{

    function __construct(){
        $this->open('chat.db');
        $this->exec('CREATE TABLE IF NOT EXISTS "users" (
                        `id`    INTEGER PRIMARY KEY AUTOINCREMENT,
                        `username`  VARCHAR(30) NOT NULL,
                        `status`    VARCHAR(15) NOT NULL,
                        `date_created`  VARCHAR(40) NOT NULL
                    )');
    }
}


$conn = new SQLiteDb();

$sql = "INSERT INTO users (username, status, date_created) VALUES ('test','active','23/09/2015 14:44'); SELECT last_insert_rowid() AS last_id;"


$lastId = $conn->querySingle($sql); 
var_dump($lastId);//returns null


$lastId = $conn->query($sql); 
var_dump($lastId); //returns object(SQLite3Result)[3]
var_dump($lastId->fetchArray(SQLITE3_ASSOC)); //returns false

Aucun commentaire:

Enregistrer un commentaire