Good day. Please tell me who knows why this code does not work:

$db = new SQLite3("KOnATbl4.sqlite"); $db->exec('CREATE TABLE base (name STRING, city STRING, home INTEGER)'); $db->exec("INSERT INTO base VALUES ('John', 'Moscow', 12)"); $results = $db->query("SELECT name, city, home FROM base"); 

Nothing is added to the database ... And the following code (for working with the received data) does not work ... Added data to the manual via the SQlite Manager, everything worked ..

  • Because you create / select from the base table, and add to the top? - etki
  • No :-) I corrected this, and did not correct it ... - istimbi
  • And by the way hello again Fike - istimbi
  • I thought that perhaps the reason is that the database does not have the necessary access rights (for writing), but this is not the case ... - istimbi
  • commit unless php after recording is not needed? - Sergey White

1 answer 1

The point is in the syntax used by the extension. It is not the data itself that is returned, but the SQLite3Result object, which assumes the following reference:

 while ($row = $results->fetchArray()) { var_dump($row); // вот здесь-то данные и лежат } 

And if it is warded, then it seems that it is empty.

  • You did not understand me .... I dropped the code that does not do what I have to ... What I dropped should create the database and add data to the table. This is not happening. In general, all the code looks like this: $ db = new SQLite3 ("KOnATbl4.sqlite"); $ db-> exec ('CREATE TABLE base (name STRING, city STRING, home INTEGER)'); // $ db-> exec ("INSERT INTO base VALUES ('John', 'Moscow', 12)"); $ results = $ db-> query ("SELECT name, city, home FROM base"); $ p = 0; while ($ row = $ results-> fetchArray ()) {$ p + = $ row ['home'] * 3; echo $ p; } - istimbi
  • @istimbi, is the database file itself being created? - etki
  • No ... And I do not understand why :-( - istimbi
  • Does the user who executes the PCP code have rights to the folder? And it is better to specify the absolute path, of course. - etki
  • Fike, I set foot :-), or rather I did not know (due to lack of experience) that I also had to set the recording rights on the folder ... Thanks for the help. - istimbi