Example #1
0
 function run_query($sql)
 {
     if ($this->debug == "on") {
         $stimer = explode(' ', microtime());
         $stimer = $stimer[1] + $stimer[0];
         $this->sqlstatments .= "{$sql}";
     }
     $db = $this->db;
     $t = new Table();
     $rows = 0;
     $insertid = "0";
     if ($db) {
         $result = mysql_query($sql, $db);
         if ($result) {
             if (preg_match("/^SELECT|^SHOW/i", $sql)) {
                 $rows = mysql_num_rows($result);
                 for ($r = 0; $r < $rows; $r++) {
                     $re = mysql_fetch_assoc($result);
                     $t->add_record($re);
                 }
             }
             if (preg_match("/^INSERT/i", $sql)) {
                 $insertid = mysql_insert_id();
             }
         } elseif ($this->debug == "on") {
             $this->sqlstatments .= "*** Error  ***\n";
             $this->sqlstatments .= mysql_errno($db);
             $this->sqlstatments .= mysql_error($db) . "\n\n";
         }
     } else {
         $t = false;
     }
     $t->setnrrows($rows);
     $t->setlastid($insertid);
     if ($this->debug == "on") {
         $etimer = explode(' ', microtime());
         $etimer = $etimer[1] + $etimer[0];
         $this->sqlstatments .= "\n" . ($etimer - $stimer) . " " . $this->text['seconds'] . "";
         $this->sqlstatments .= ", {$rows} rows\n";
     }
     return $t;
 }