R
R
Roman Radic2016-04-25 13:59:48
PHP
Roman Radic, 2016-04-25 13:59:48

I don’t understand why the PHP code for adding a query to SQLite3 does not work?

Help, I'm really confused. I started to study OOP in PHP, I wrote such an elementary code and I don’t understand why it doesn’t work.

$title = "Item1";
$category = 1;
$description = "Item2";
$source = "Item3";

$db = new SQLite3('DB.sqlite3');
$sql = "CREATE TABLE msgs (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            title TEXT,
            category INTEGER,
            description TEXT,
            source TEXT
            ) ";

$db->exec($sql);
unset($db);

This part of the code works fine, a database file is created with the msgs table and fields.
Next, I'm trying to add data to the table.
$sql_insert = "INSERT INTO msgs (
                    title,
                    category,
                    description,
                    source )
                VALUES (
                    $title,
                    $category,
                    $description,
                    $source
                )";

$db = new SQLite3('DB.sqlite3');
$db->exec($sql_insert);

Throws an error: Warning: SQLite3::exec(): no such column: Item1 in /var/www/html/news/test.php on line 37

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2016-04-25
@user28

Who will screen.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question