note 45078 added to function.sqlite-query
| From: | webmasteratphp5infodotcom at osu1 dot php dot net | Date: | Wed, 25 Aug 2004 16:14:09 +0000 |
| Subject: | note 45078 added to function.sqlite-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75246@lists.php.net to get a copy of this message | ||
I found an easier way to insert multiples queries with sqlite_query. Less code is better :)
First, you need to store your SQL queries. Do not forget to seperate each query with ";".
One query = one line
$db = sqlite_open('resahotel', 0666, $sqliteerror); // resahotel is the db name created or
accessed
$sql = "CREATE TABLE CLIENT (ID INTEGER NOT NULL PRIMARY KEY, NOM VARCHAR(50), ADRESSE_RUE
VARCHAR(100), ADRESSE_CP INTEGER, ADRESSE_VILLE VARCHAR(30), PAYS VARCHAR(30));
INSERT INTO CLIENT (NOM, ADRESSE_RUE, ADRESSE_CP, ADRESSE_VILLE, PAYS) VALUES ('DURAND',
'48 rue de l Elysée', '38000','Grenoble','France');
INSERT INTO CLIENT (NOM, ADRESSE_RUE, ADRESSE_CP, ADRESSE_VILLE, PAYS) VALUES ('DUPONT',
'17 rue du Sentier', '74000','Annecy','France');
INSERT INTO CLIENT (NOM, ADRESSE_RUE, ADRESSE_CP, ADRESSE_VILLE, PAYS) VALUES ('GARNIER',
'147 avenue Victor Hugo', '62110','Henin
Beaumont','France');
INSERT INTO CLIENT (NOM, ADRESSE_RUE, ADRESSE_CP, ADRESSE_VILLE, PAYS) VALUES ('DUPONT',
'20 rue Royale', '74000','Annecy','France');
SELECT NOM FROM CLIENT WHERE ADRESSE_VILLE='Annecy';
"; // queries separated with ";" - 1 SQL query = 1 line !
function multipleSqliteQueries($db,$sql)
{
$array = explode("\n",$sql);
for($i=0;$i < count($array)-1;$i++)
{
sqlite_query($db,$array[$i]);
echo "Requète ".$i." (".$array[$i].") -> OK !<br>\n"; //
show the result
}
}
multipleSqliteQueries($db,$sql); // call the function
TEAM17
----
Manual Page -- http://www.php.net/manual/en/function.sqlite-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45078
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45078&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45078&report=yes
Search -- http://master.php.net/manage/user-notes.php