/** * Runs a single statement and times it, removes any old unbuffered queries before starting * * @param string|fStatement $statement The SQL statement or prepared statement to execute * @param string $result_type The type of result object to return, fResult or fUnbufferedResult * @return fResult|fUnbufferedResult The result for the query */ private function run($statement, $result_type = NULL, $params = array()) { if ($this->unbuffered_result) { $this->unbuffered_result->__destruct(); $this->unbuffered_result = NULL; } $start_time = microtime(TRUE); if (is_object($statement)) { $sql = $statement->getSQL(); } else { $sql = $statement; } if (!($result = $this->handleTransactionQueries($sql, $result_type))) { if ($result_type) { $result = new $result_type($this, $this->type == 'mssql' ? $this->schema_info['character_set'] : NULL); $result->setSQL($sql); if ($result_type == 'fResult') { $this->performQuery($statement, $result, $params); } else { $this->performUnbufferedQuery($statement, $result, $params); } } else { $this->perform($statement, $params); } } // Write some debugging info $query_time = microtime(TRUE) - $start_time; $this->query_time += $query_time; if (fCore::getDebug($this->debug)) { fCore::debug(self::compose('Query time was %1$s seconds for:%2$s', $query_time, "\n" . $sql), $this->debug); } if ($this->hook_callbacks['run']) { foreach ($this->hook_callbacks['run'] as $callback) { $callback_params = array($this, is_object($statement) ? array($statement, $params) : $sql, $query_time, $result); call_user_func_array($callback, $callback_params); } } if ($result_type) { return $result; } }
/** * Runs a single statement and times it, removes any old unbuffered queries before starting * * @param string|fStatement $statement The SQL statement or prepared statement to execute * @param string $result_type The type of result object to return, fResult or fUnbufferedResult * @return fResult|fUnbufferedResult The result for the query */ private function run($statement, $result_type = NULL, $params = array()) { if ($this->unbuffered_result) { $this->unbuffered_result->__destruct(); $this->unbuffered_result = NULL; } $start_time = microtime(TRUE); if (is_object($statement)) { $sql = $statement->getSQL(); } else { $sql = $statement; } if (!($result = $this->handleTransactionQueries($sql, $result_type))) { if ($result_type) { $result = new $result_type($this, $this->type == 'mssql' ? $this->schema_info['character_set'] : NULL); $result->setSQL($sql); if ($result_type == 'fResult') { $this->performQuery($statement, $result, $params); } else { $this->performUnbufferedQuery($statement, $result, $params); } } else { $this->perform($statement, $params); } } // Write some debugging info $query_time = microtime(TRUE) - $start_time; $this->query_time += $query_time; if (fCore::getDebug($this->debug)) { fCore::debug(self::compose('Query time was %1$s seconds for:%2$s', $query_time, "\n" . $sql), $this->debug); } if ($this->slow_query_threshold && $query_time > $this->slow_query_threshold) { trigger_error(self::compose('The following query took %1$s milliseconds, which is above the slow query threshold of %2$s:%3$s', $query_time, $this->slow_query_threshold, "\n" . $sql), E_USER_WARNING); } if ($result_type) { return $result; } }
/** * Sends commands to the IMAP or POP3 server * * @param string $command The command to send * @param integer $expected The number of lines or regex expected for a POP3 command * @return array The response from the server */ private function write($command, $expected = NULL) { if (!$this->connection) { throw new fProgrammerException('Unable to send data since the connection has already been closed'); } if ($this->type == 'imap') { $identifier = 'a' . str_pad($this->command_num++, 4, '0', STR_PAD_LEFT); $command = $identifier . ' ' . $command; } if (substr($command, -2) != "\r\n") { $command .= "\r\n"; } if (fCore::getDebug($this->debug)) { fCore::debug("Sending:\n" . trim($command), $this->debug); } $res = fwrite($this->connection, $command); if ($res === FALSE) { throw new fConnectivityException('Unable to write data to %1$s server %2$s on port %3$s', strtoupper($this->type), $this->host, $this->port); } if ($this->type == 'imap') { return $this->read('#^' . $identifier . '#'); } elseif ($this->type == 'pop3') { return $this->read($expected); } }
/** * Sends raw text/commands to the SMTP server * * @param string $data The data or commands to send * @param integer|string $expect The expected number of lines of response or a regex of the last line * @return array The response from the server */ private function write($data, $expect) { if (!$this->connection) { throw new fProgrammerException('Unable to send data since the connection has already been closed'); } if (substr($data, -2) != "\r\n") { $data .= "\r\n"; } if (fCore::getDebug($this->debug)) { fCore::debug("Sending:\n" . trim($data), $this->debug); } $res = fwrite($this->connection, $data); if ($res === FALSE || $res === 0) { throw new fConnectivityException('Unable to write data to SMTP server %1$s on port %2$s', $this->host, $this->port); } $response = $this->read($expect); return $response; }