Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/SQLite with multiple SQL statements: $db->Query() works, $this->db_sqlite->query() fails
    primarykey
    data
    text
    <p>I am creating a class that handles various SQLite actions. My problem is: When I make a SQL string with multiple statements then it works when using standard PHP => $db->query() ... but it fails when making the same request from a method. It seems that the OO method skips everything after the first ";"-symbol in my SQL statement. Why is that, and how to fix it?</p> <p>Thanks.</p> <pre><code>// Fails - line 2 is not inserted, why? $this-&gt;db_sqlite-&gt;query(" INSERT INTO foo (name) VALUES('Via class multi-lines 1'); INSERT INTO foo (name) VALUES('Via class multi-lines 2'); "); // Works - both lines are inserted. $GLOBALS[db]-&gt;query(" INSERT INTO foo (name) VALUES('Direct multi-lines 1'); INSERT INTO foo (name) VALUES('Direct multi-lines 2'); "); </code></pre> <p>Full example:</p> <pre><code>&lt;?php class db_sqlite { function __construct() { $this-&gt;connect(); } function connect() { $GLOBALS[db] = new SQLiteDatabase("dbsqlite.php.db"); } function query($sql) { return $GLOBALS[db]-&gt;query($sql); } } class something { function setup() { $this-&gt;db_sqlite = new db_sqlite(); $this-&gt;db_sqlite-&gt;query("CREATE TABLE foo ( id INTEGER PRIMARY KEY, name CHAR(255) );"); // Works $this-&gt;db_sqlite-&gt;query("INSERT INTO foo (name) VALUES('Via class one line 1');"); $this-&gt;db_sqlite-&gt;query("INSERT INTO foo (name) VALUES('Via class one line 2');"); // Fails (why?) $this-&gt;db_sqlite-&gt;query(" INSERT INTO foo (name) VALUES('Via class multi-lines 1'); INSERT INTO foo (name) VALUES('Via class multi-lines 2'); "); // Works $GLOBALS[db]-&gt;query(" INSERT INTO foo (name) VALUES('Direct multi-lines 1'); INSERT INTO foo (name) VALUES('Direct multi-lines 2'); "); foreach($this-&gt;db_sqlite-&gt;query("SELECT * FROM foo") as $v) { echo $v[id] . " - " . $v[name] ."&lt;br&gt;"; } } } $something = new something(); $something-&gt;setup(); ?&gt; </code></pre> <p>Output:<br> 1 - Via class one line 1 (correct)<br> 2 - Via class one line 2 (correct) 3 - Via class multi-lines 1 (incorrect)<br> 4 - Direct multi-lines 1 (correct)<br> 5 - Direct multi-lines 2 (correct) </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload