<?php
/**
* @page connexion_sqlite_en_memoire.php
* @brief Exemple de connexion à une base sqlite en mémoire
*
* On l'utilise pour trier des nombres.
*
* @author hughes monget
* @see http://monget.com/
*/
highlight_file(__FILE__);
echo '<hr />';
echo '<pre>';
($res_database = sqlite_open(':memory:', 0666, $str_erreur)) || exit($str_erreur);
// varchar(100)
sqlite_exec($res_database, 'create table test (id integer primary key, data integer);', $str_erreur) || exit($str_erreur);
foreach (range(1, 100) as $ii)
{
$int_valeur = mt_rand(0, 1000);
sqlite_exec($res_database, 'insert into test(data) values ("'.$int_valeur.'");', $str_erreur) || exit($str_erreur);
echo "$int_valeur ";
}
echo '<br />';
($res_result = sqlite_query($res_database, 'select * from test order by data asc;', SQLITE_NUM, $str_erreur)) || exit($str_erreur);
echo '<table border="0"><tr><th>id</th><th>data</th></tr>';
while ($arr_tuple = sqlite_fetch_array($res_result, SQLITE_NUM))
{
list($id, $data) = $arr_tuple;
echo "<tr><td>$id</td><td>$data</td></tr>";
}
echo '</table>';
sqlite_close($res_database);
echo '</pre>';