include("lib/config.class.php");
include("lib/db.mysql.class.php");
$db = DB::getInstance();
//-------- SELECT --------
$sql = "SELECT * FROM news LIMIT 0,10";
$result = $db->query($sql);
$rows = $db->fetch_all();
if ($rows) {
foreach ($rows as $row) {
print_r($row);
}
}
//-------- UPDATE --------
$sql = "UPDATE news SET nid=3 WHERE nid=3";
$result = $db->query($sql);
//-------- INSERT + LAST_INSERT_ID --------
$sql = "INSERT INTO news (nid, dt, title, full_text)
VALUES ('', NOW(), 'Example title', 'Example text')";
$result = $db->query($sql);
echo 'LAST_INSERT_ID = ' . $db->insert_id() . "<br />";
//-------- DELETE --------
$sql = "DELETE FROM news WHERE nid=5";
$result = $db->query($sql);
//------- DEBUG, show count of queries, list of all queries --------
if ($db->debug && isset($db->queries)) {
$mysql_time = '';
echo '<hr noshade />';
foreach ($db->queries as $query) {
echo '<pre>' . $query['query'] . '</pre>run: ' . sprintf("%01.6f", $query['time']) . ' sec.<hr noshade />';
$mysql_time += $query['time'];
}
echo 'Total queries: <b>' . count($db->queries) . '</b> (' . sprintf("%01.6f", $mysql_time) . ' sec.), ';
echo 'Mysql traffic: <b>' . number_format($db->getTotalTraffic() / 1024, 1, '.', ' ') . 'Kb</b>.<hr noshade />';
}
}