Beispiel #1
0
 /** @api */
 function execSql($s, $silent = false)
 {
     $rv = null;
     if (preg_match('/^\\s*select/i', $s)) {
         $sth = $this->dbh->query($s);
         $rv = $sth->fetchAll(\PDO::FETCH_ASSOC);
         if (!$silent) {
             print_rs($rv);
         }
     } else {
         $rv = $this->dbh->exec($s);
         if (!$silent) {
             echo "=== {$rv} records Affected.\n";
         }
     }
     return $rv;
 }
Beispiel #2
0
<html>
<body>
<?php 
function print_rs($recordset)
{
    while ($row = $recordset->fetch_assoc()) {
        print_r($row);
    }
}
$db = mysql_connect();
$result = mysql_query('SELECT NOW();');
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
echo $db;
echo "<br>";
echo $result;
echo "<br>";
print_rs($result);
echo "<br>";
echo date("Y-m-d H:i:s");
echo "<br>";
echo "<br>";
echo "Try a <a href='/HelloWorld'>servlet</a>!";
?>
</body>
</html>