/** * This method is used to delete record(s) from * a table in the db. * * @param string the table name * @param string the where clause condition * NOTE: this doesn't include the 'where' word. * Example: 'siteid=:siteid and foo=:foo' * @param array the bind vars that live in the where clause * Example: array(':siteid' => 69, * ':foo' => 'blah blah'); * @return boolean TRUE = success */ public function delete($table, $where_condition = NULL, $bind_vars = array()) { $sql = 'DELETE FROM ' . $table; if (!is_null($where_condition)) { $sql .= ' WHERE ' . $where_condition; Logger::Notice("Execute query: '" . $sql . "' " . print_ln($bind_vars, true)); //we now have to prepare the query //and bind all of the values. try { $stmt = $this->db->prepare($sql); } catch (PDOException $e) { //throw new DataBaseException($e->getMessage(), $e->getCode(), $sql, $bind_vars); throw $e; } //ok now bind the parameters //first bind the user provided vars if (!empty($bind_vars)) { $i = 1; foreach ($bind_vars as $key => $value) { // determine if this is binding by ? or by :name $key = $key[0] == ":" ? $key : $i; $stmt->bindValue($key, $value); $i++; } } } else { //we now have to prepare the query //and bind all of the values. $stmt = $this->db->prepare($sql); } //and now execute it! $result = $stmt->execute(); Logger::Debug("Database::delete() - {$sql}"); return $result; }
protected static function composeMessage($lvl, $msg, $args) { if (!empty($args)) { $msg = vsprintf($msg, $args); } $msg_body = "MESSAGE = "; $msg_body .= is_object($msg) || is_array($msg) ? print_ln($msg, true) : $msg; /* $msg_header = self::NEWLINE . "=== " . "Log[" . self::levelToString($lvl) . "] - " . date(DATE_RFC822); $backtrace = debug_backtrace(); $msg_trace = self::NEWLINE . "HTTP_HOST = " . $_SERVER["HTTP_HOST"] . self::NEWLINE . "REQ = " . $_SERVER["REQUEST_URI"] . self::NEWLINE . "FILE = " . $backtrace[2]["file"] . self::NEWLINE . "LINE = " . $backtrace[2]["line"]; //. self::NEWLINE . "ARGS = " . print_r($args, true); return($msg_header . self::NEWLINE . $msg_trace . self::NEWLINE . $msg_body); */ $msg = date("M j G:i:s") . "\t" . self::levelToString($lvl) . "\t" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\t" . $msg_body; return $msg; }
function controller($argv) { if (!$argv[2]) { print_ln("no controller name given"); exit; } $controllerName = mb_convert_case($argv[2], MB_CASE_TITLE); // creating controller file $controllerFile = "application/controllers/" . $controllerName . "Controller.php"; if (file_exists($controllerFile)) { print_ln("exists: " . $controllerFile); } else { touch($controllerFile); file_put_contents($controllerFile, zendControllerCodeForControllerNamed($controllerName, $argv)); print_ln("create: " . $controllerFile); } // creating view script $viewScriptDir = "application/views/scripts/" . strtolower($controllerName); if (file_exists($viewScriptDir)) { print_ln("exists: " . $viewScriptDir); } else { mkdir($viewScriptDir); print_ln("create: " . $viewScriptDir); } for ($i = 3; $i < count($argv); $i++) { $viewScriptFile = $viewScriptDir . "/" . strtolower($argv[$i] . ".phtml"); if (file_exists($viewScriptFile)) { print_ln("exists: " . $viewScriptFile); } else { touch($viewScriptFile); print_ln("create: " . $viewScriptFile); } } }
function print_h($a) { print_n(""); print_n($a); print_ln(); }
function xml_to_wbxml($msg_body) { $wbxmlfile = 'xml2wbxml_' . md5(uniqid(time())) . '.wbxml'; $xmlfile = 'xml2wbxml_' . md5(uniqid(time())) . '.xml'; //create temp file $fp = fopen($xmlfile, 'w+'); fwrite($fp, $msg_body); fclose($fp); //convert temp file exec(xml2wbxml . ' -v 1.2 -o ' . $wbxmlfile . ' ' . $xmlfile . ' 2>/dev/null'); if (!file_exists($wbxmlfile)) { print_ln('Fatal error: xml2wbxml conversion failed'); return false; } $wbxml = trim(file_get_contents($wbxmlfile)); //remove temp files unlink($xmlfile); unlink($wbxmlfile); return $wbxml; }