function sql($sqlFmt, $ra = array()) { $ret = false; // connect to server if (!$this->link) { $this->link = mysql_pconnect($this->host, $this->user, $this->pass); // select database if ($this->link) { if (mysql_select_db($this->db, $this->link)) { mysql_query("SET NAMES 'utf8'", $this->link); } else { mysql_close($this->link); $this->link = NULL; } } } // query if ($this->link) { // protect data foreach ($ra as $k => $i) { $ra[$k] = mysql_real_escape_string($i, $this->link); } // print variables into sql statement $sql = vsprintf($sqlFmt, $ra); // execute //funx::debug("Executing SQL: |$sql|"); $ret = mysql_query($sql, $this->link); // error? if (!$ret) { $msg = "DB Error: " . mysql_error($this->link) . "\nExecuting SQL: {$sql}\n"; if (funx::isCommandline()) { echo $msg; } else { funx::debug($msg); email::send(ini::get('email-address'), 'DB Error', $msg); } } } else { echo "Database connection couldn't be established\n"; } return $ret; }