public function execute($query, $arguments = []) { $split = preg_split('/({\\w+})/', $query, -1, PREG_SPLIT_DELIM_CAPTURE); $count = count($split); for ($i = 1; $i < $count; $i += 2) { $key = $split[$i]; if (array_key_exists($key, $arguments)) { // found a replacement in $arguments. $split[$i] = $arguments[$key]; } } $query = join($split); // create a PDO statment $this->last_stmt = $st = $this->link->prepare($query); if ($st === false) { $this->last_stmt = null; return false; } // forward :args to PDO. $pdo_args = []; foreach ($arguments as $key => $value) { if ($key[0] == ':') { $pdo_args[$key] = $value; } } No2_Logger::debug('PDO->execute: ' . preg_replace('/\\s+/m', ' ', $query)); return $st->execute($pdo_args) ? $st : false; }
function test_output_format() { $date = preg_quote(date(DateTime::ISO8601), '/'); $reqid = preg_quote(No2_Logger::$reqid, '/'); $this->expectOutputRegex("/^\\[PHPUnit {$date} {$reqid}\\] DEBUG: test\$/"); No2_Logger::debug('test'); print file_get_contents(static::$LOGFILE_PATH); }
/** * make a SQL query to the database. the query should be properly escaped. * * @see http://php.net/manual/en/function.mysql-query.php */ public function query($query) { global $wpdb; if (preg_match('/\\s*select/i', $query)) { No2_Logger::debug('$wpdb->get_results: ' . preg_replace('/\\s+/m', ' ', $query)); $result = $wpdb->get_results($query, ARRAY_A); if (is_array($result)) { $index = count($this->results); $this->results[$index] = $result; $result = (object) array($index); // return the index as an object. } } else { No2_Logger::debug('$wpdb->query: ' . preg_replace('/\\s+/m', ' ', $query)); $result = $wpdb->query($query); } return $result; }
/** * make a SQL query to the database. the query should be properly escaped * since it will be directly passed to mysql_query(). * * @see http://php.net/manual/en/function.mysql-query.php */ public function query($query) { No2_Logger::debug('mysql_query: ' . preg_replace('/\\s+/m', ' ', $query)); $result = mysql_query($query, $this->link); return $result; }