本文整理汇总了PHP中Connection::executeQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::executeQuery方法的具体用法?PHP Connection::executeQuery怎么用?PHP Connection::executeQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::executeQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
ActiveRecordModel::getApplication()->clearCachedVars();
ActiveRecordModel::beginTransaction();
if (empty($this->autoincrements)) {
foreach ($this->getUsedSchemas() as $table) {
$res = $this->db->executeQuery("SHOW TABLE STATUS LIKE '{$table}'");
$res->next();
$this->autoincrements[$table] = (int) $res->getInt("Auto_increment");
}
}
if ($this instanceof BackendControllerTestCase) {
ClassLoader::import('application.model.user.SessionUser');
ClassLoader::import('application.model.user.UserGroup');
// set up user
$group = UserGroup::getNewInstance('Unit tester');
$group->save();
$group->setAllRoles();
$group->save();
$user = User::getNewInstance('unittest@test.com', null, $group);
$user->save();
SessionUser::setUser($user);
}
if ($this instanceof ControllerTestCase) {
$this->request = self::getApplication()->getRequest();
}
}
示例2: executeQuery
/**
* Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.
* We support two signatures for this method:
* - $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
* - $stmt->executeQuery(array($param1, $param2), ResultSet::FETCHMODE_NUM);
* @param mixed $p1 Either (array) Parameters that will be set using PreparedStatement::set() before query is executed or (int) fetchmode.
* @param int $fetchmode The mode to use when fetching the results (e.g. ResultSet::FETCHMODE_NUM, ResultSet::FETCHMODE_ASSOC).
* @return ResultSet
* @throws SQLException if a database access error occurs.
*/
public function executeQuery($p1 = null, $fetchmode = null)
{
$params = null;
if ($fetchmode !== null) {
$params = $p1;
} elseif ($p1 !== null) {
if (is_array($p1)) {
$params = $p1;
} else {
$fetchmode = $p1;
}
}
if ($params) {
for ($i = 0, $cnt = count($params); $i < $cnt; $i++) {
$this->set($i + 1, $params[$i]);
}
}
$this->updateCount = null;
// reset
$sql = $this->replaceParams();
if ($this->limit > 0 || $this->offset > 0) {
$this->conn->applyLimit($sql, $this->offset, $this->limit);
}
$this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
return $this->resultSet;
}
示例3: executeQuery
/**
* Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.
* We support two signatures for this method:
* - $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
* - $stmt->executeQuery(array($param1, $param2), ResultSet::FETCHMODE_NUM);
* @param mixed $p1 Either (array) Parameters that will be set using PreparedStatement::set() before query is executed or (int) fetchmode.
* @param int $fetchmode The mode to use when fetching the results (e.g. ResultSet::FETCHMODE_NUM, ResultSet::FETCHMODE_ASSOC).
* @return ResultSet
* @throws SQLException if a database access error occurs.
*/
public function executeQuery($p1 = null, $fetchmode = null)
{
$params = null;
if ($fetchmode !== null) {
$params = $p1;
} elseif ($p1 !== null) {
if (is_array($p1)) {
$params = $p1;
} else {
$fetchmode = $p1;
}
}
foreach ((array) $params as $i => $param) {
$this->set($i + 1, $param);
unset($i, $param);
}
unset($params);
$this->updateCount = null;
// reset
$sql = $this->replaceParams();
if ($this->limit > 0 || $this->offset > 0) {
$this->conn->applyLimit($sql, $this->offset, $this->limit);
}
$this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
return $this->resultSet;
}
示例4: executeQuery
/**
* @see Connection::executeQuery()
*/
public function executeQuery($sql, $fetchmode = null)
{
$this->log("executeQuery(): {$sql}");
$this->lastExecutedQuery = $sql;
$this->numQueriesExecuted++;
return $this->childConnection->executeQuery($sql, $fetchmode);
}
示例5: executeQuery
/**
* Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.
*
* @param string $sql This method may optionally be called with the SQL statement.
* @param int $fetchmode The mode to use when fetching the results (e.g. ResultSet::FETCHMODE_NUM, ResultSet::FETCHMODE_ASSOC).
* @return object Creole::ResultSet
* @throws SQLException If there is an error executing the specified query.
* @todo -cStatementCommon Put native query execution logic in statement subclasses.
*/
public function executeQuery($sql, $fetchmode = null)
{
$this->updateCount = null;
if ($this->limit > 0 || $this->offset > 0) {
$this->conn->applyLimit($sql, $this->offset, $this->limit);
}
$this->resultSet = $this->conn->executeQuery($sql, $fetchmode);
return $this->resultSet;
}
示例6: executeQuery
/**
* @see Connection::executeQuery()
*/
public function executeQuery($sql, $fetchmode = null)
{
$this->lastExecutedQuery = $sql;
$this->numQueriesExecuted++;
$startTime = microtime(true);
$res = $this->childConnection->executeQuery($sql, $fetchmode);
$endTime = microtime(true);
$time = $endTime - $startTime;
$this->log("executeQuery|{$time}|{$sql}");
return $res;
}
示例7: OnCheckNeuanmeldungen
public static function OnCheckNeuanmeldungen(Connection $conn, ErrorQueue $err)
{
$returnvalue = true;
$jetzt = strtotime("now");
$q = new DBQuery("SELECT MatrNr FROM neuanmeldung WHERE DeleteAfter < {$jetzt}");
if ($result = $conn->executeQuery($q)) {
while ($r = $result->getNextRow()) {
$delq = new DBQuery("DELETE FROM student WHERE MatrNr=" . $r[0]);
$delq2 = new DBQuery("DELETE FROM neuanmeldung WHERE MatrNr={$matrnr}");
if (false == $conn->executeQuery($delq)) {
ErrorQueue::SystemErrorConnection("TriggerStudent.php", "OnCheckNeuanmeldungen", $conn);
$returnvalue = false;
}
}
} else {
ErrorQueue::SystemErrorConnection("TriggerStudent.php", "OnCheckNeuanmeldungen", $conn);
$returnvalue = false;
}
return $returnvalue;
}
示例8: writepass
private function writepass(Connection $conn, $matrnr, $pass)
{
$pass = md5($pass);
$matrnr = intval($matrnr);
if ($conn->isConnected()) {
// Email des Studenten auslesen
$q = new DBQuery("SELECT Email FROM student WHERE MatrNr={$matrnr}");
if ($res = $conn->executeQuery($q)) {
if ($r = $res->getNextRow()) {
$email = $r[0];
} else {
$this->last_error = "Die Matrikelnummer existiert nicht.";
return false;
}
} else {
$this->last_error = "Die Matrikelnummer konnte nicht überprüft werden. " . $conn->getLastError();
return false;
}
// Das neue Passwort wird geschrieben
$q = new DBQuery("UPDATE student SET Pass='{$pass}' WHERE MatrNr={$matrnr}");
if ($res = $conn->executeQuery($q)) {
if ($res->affectedRows() > 0) {
return $email;
} else {
$this->last_error = "Die Matrikelnummer existiert nicht.";
return false;
}
} else {
$this->last_error = "Die Passwortänderung konnte nicht durchgeführt werden. " . $conn->getLastError();
return false;
}
} else {
$this->last_error = "Keine Verbindung zur Datenbank.";
return false;
}
}
示例9: getUtilisateurAvecLogin
public static function getUtilisateurAvecLogin($login, $mdp)
{
$connexion = new Connection(Config::getDataBaseInfos()['DBname'], Config::getDataBaseInfos()['login'], Config::getDataBaseInfos()['mdp'], null);
$requete = "SELECT login, mdp, role FROM Utilisateur WHERE login='{$login}'";
$connexion->executeQuery($requete);
$result = $connexion->getResults();
if (count($result) == 0) {
Config::ajouterErreur("Login ou mot de passe de passe incorrect");
}
$result = $result[0];
if ($result['login'] == $login && $result['mdp'] == $mdp) {
return self::returnBonTypeUtilisateur($result['login'], $result['role']);
}
Config::ajouterErreur("Login ou mot de passe de passe incorrect");
return null;
}
示例10: resynchronizeDatabaseSequences
/**
* @brief Resynchronizes all sequences of a database after using INSERTs
* without leaving out the auto-incremented column.
* @param \OC\DB\Connection $conn
* @return null
*/
public function resynchronizeDatabaseSequences(Connection $conn)
{
$databaseName = $conn->getDatabase();
foreach ($conn->getSchemaManager()->listSequences() as $sequence) {
$sequenceName = $sequence->getName();
$sqlInfo = 'SELECT table_schema, table_name, column_name
FROM information_schema.columns
WHERE column_default = ? AND table_catalog = ?';
$sequenceInfo = $conn->fetchAssoc($sqlInfo, array("nextval('{$sequenceName}'::regclass)", $databaseName));
$tableName = $sequenceInfo['table_name'];
$columnName = $sequenceInfo['column_name'];
$sqlMaxId = "SELECT MAX({$columnName}) FROM {$tableName}";
$sqlSetval = "SELECT setval('{$sequenceName}', ({$sqlMaxId}))";
$conn->executeQuery($sqlSetval);
}
}
示例11: executeQuery
/**
* @see Connection::executeQuery()
*/
public function executeQuery($sql, $fetchmode = null)
{
$this->lastExecutedQuery = $sql;
$this->numQueriesExecuted++;
$elapsedTime = 0;
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
$sqlTimer = sfTimerManager::getTimer('Database');
$timer = new sfTimer();
}
$retval = $this->childConnection->executeQuery($sql, $fetchmode);
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
$sqlTimer->addTime();
$elapsedTime = $timer->getElapsedTime();
}
$this->log(sprintf("executeQuery(): [%.2f ms] %s", $elapsedTime * 1000, $sql));
return $retval;
}
示例12: sessionGC
/**
* Cleanup old sessions.
*
* @param int The lifetime of a session.
*
* @return bool true, if old sessions have been cleaned, otherwise an
* exception is thrown.
*
* @throws <b>DatabaseException</b> If any old sessions cannot be cleaned.
*/
public function sessionGC($lifetime)
{
// determine deletable session time
$time = time() - $lifetime;
// get table/column
$db_table = $this->getParameterHolder()->get('db_table');
$db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time');
// delete the record associated with this id
$sql = 'DELETE FROM ' . $db_table . ' ' . 'WHERE ' . $db_time_col . ' < ' . $time;
try {
$this->db->executeQuery($sql);
return true;
} catch (SQLException $e) {
$error = 'Creole SQLException was thrown when trying to manipulate session data. ';
$error .= 'Message: ' . $e->getMessage();
throw new sfDatabaseException($error);
}
}
示例13: executeQuery
/**
* @see Connection::executeQuery()
*/
public function executeQuery($sql, $fetchmode = null)
{
$this->lastExecutedQuery = $sql;
$this->numQueriesExecuted++;
$boolLog = sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled') || nyProfiler::getInstance()->isStarted();
$elapsedTime = 0;
if ($boolLog) {
$sqlTimer = sfTimerManager::getTimer('Database');
$timer = new sfTimer();
}
// endif
$retval = $this->childConnection->executeQuery($sql, $fetchmode);
if ($boolLog) {
$sqlTimer->addTime();
$elapsedTime = $timer->getElapsedTime();
}
// endif
$this->log(sprintf("{sfCreole} executeQuery(): [%.2f ms] %s", $elapsedTime * 1000, $sql), true);
return $retval;
}
示例14: testRollback
public function testRollback()
{
$exch = DriverTestManager::getExchange('RecordCount');
$count_sql = $exch->getSql();
$rs = $this->conn->executeQuery($count_sql, ResultSet::FETCHMODE_NUM);
$rs->next();
$total = $rs->getInt(1);
// $this->assertEquals((int) $exch->getResult(), $total);
$this->conn->setAutoCommit(false);
// not sure exactly how to test this yet ...
$exch = DriverTestManager::getExchange('ConnectionTest.setAutoCommit.DELTRAN1');
$deleted1 = $this->conn->executeUpdate($exch->getSql());
$exch = DriverTestManager::getExchange('ConnectionTest.setAutoCommit.DELTRAN2');
$deleted2 = $this->conn->executeUpdate($exch->getSql());
$this->conn->rollback();
// compare the actual total w/ what we expect
$rs = $this->conn->executeQuery($count_sql, ResultSet::FETCHMODE_NUM);
$rs->next();
$new_actual_total = $rs->getInt(1);
$this->assertEquals($total, $new_actual_total, 0, "Failed to find correct (same) num of records in table after rollback().");
$this->conn->setAutoCommit(true);
}
示例15: json_encode
<?php
require_once 'Connection.php';
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$connection = new Connection($request->connection->host, $request->connection->database, $request->connection->user, $request->connection->pass);
if (empty($connection->message)) {
$connection->executeQuery($request->query);
}
echo json_encode(array('status' => $connection->status, 'message' => $connection->message));