T
T
true2021-12-30 21:29:05
PHP
true, 2021-12-30 21:29:05

Where is the error in the database query?

<?php

$db = new SQLite3("test.db"); 

$sql = "CREATE TABLE таблица1(
    id INTEGER PRIMARY KEY 
      столбец1 TEXT,
      столбец2 TEXT
      );";
 
$db->query($sql);

$sql = "INSERT INTO таблица1 ('папапп', 'кекекек') ;";

$db->query($sql);

$sql = "SELECT столбец1, столбец2 FROM таблица1 ;";  

$result_array = $db->array_query($sql, SQLITE_ASSOC);  //тут ошибка

print json_encode($result_array);

?>


I need to get the data in the form of an array

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2021-12-30
@RAFAILgaley

Errors in SQL queries

$sql = "CREATE TABLE таблица1(
    id INTEGER PRIMARY KEY,
    col1 INT,
    col2 TEXT
);";
 
$db->exec($sql);

$sql = "INSERT INTO таблица1(col1, col2) VALUES 
  ('aaaa', 'bbbbb'),
  ('xxx', 'yyy');";

$db->exec($sql);

$sql = "SELECT * FROM таблица1;";  

$result = $db->query($sql);

while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
  $array[] = $row;
}
print json_encode($array);

PHP SQLite sandbox

S
Sergey Karbivnichy, 2021-12-30
@hottabxp

Well, let's play a guessing game.
In request

$sql = "INSERT INTO таблица1 ('папапп', 'кекекек') ;";
shouldn't it be VALUES? Although I could be wrong.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question