本文整理汇总了PHP中MySQLi::query方法的典型用法代码示例。如果您正苦于以下问题:PHP MySQLi::query方法的具体用法?PHP MySQLi::query怎么用?PHP MySQLi::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySQLi
的用法示例。
在下文中一共展示了MySQLi::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
private static function query($sql)
{
if (self::$debug) {
tprintWarning($sql);
}
return self::$DB_CONN->query($sql);
}
示例2: __construct
/**
* @param \MySQLi $mysql
* @param string $query
*/
public function __construct(\MySQLi $mysql, $query)
{
$this->mysql = $mysql;
$qobject = $this->mysql->query($query);
if (substr($query, 0, strlen('INSERT INTO')) == 'INSERT INTO' || substr($query, 0, strlen('DELETE FROM')) == 'DELETE FROM') {
$this->data = false;
} else {
while ($dat = $qobject->fetch_assoc()) {
$this->data[] = $dat;
}
$qobject->close();
}
}
示例3: query
/**
* 数据库查询函数
*
* @param string $sql 查询语句
* @return mixed
*/
public static function query($sql)
{
$sql = trim($sql);
if (self::$db == NULL) {
self::_init_mysql();
}
self::$mysqli_rst = self::$db->query($sql);
if (FALSE == self::$mysqli_rst) {
echo 'MySQL query errno : ' . self::$db->errno . PHP_EOL;
$backtrace = debug_backtrace();
var_dump($backtrace);
return FALSE;
} else {
return self::$mysqli_rst;
}
}
示例4: query
function query($req)
{
// Si c'est la première requête
if ($this->reqcount == 0) {
// on ititialise les paramètres
$this->initParams();
}
// On incrémente le compteur de requêtes
$this->reqcount++;
// Si la requête n'arrive pas à s'exécuter
if (!($res = parent::query($req))) {
// On commencer à mettre la sortie dans un buffer (ob = output buffer)
ob_start();
// On affiche l'état de la pile d'appel (pour savoir pourquoi ça plante, d'uù le script est lancé)
debug_print_backtrace();
// On écrit tout ça dans un fichier de logs "mysql_errors" avec la date, l'erreur, la requête SQL associée et l'état de la pile d'appel dans le buffer
file_put_contents(FONCTIONS . "mysql_errors", date('[d/m/Y - H:i:s]') . ' Erreur MySQL : ' . $this->error . ' pendant la requête ' . $req . '
Backtrace:
' . ob_get_contents());
// On termine la capture de la sortie et on efface ce qu'on a enregistré
ob_end_clean();
// Et on termine le script.
die("Une erreur s'est produite: " . $this->error);
}
// Sinon, tout va bien, on renvoie le résultat.
return $res;
}
示例5: query
public function query($sSQL, $log = true)
{
$start = microtime(true);
$this->connect();
// Increase the counter
$this->query_counter++;
$result = $this->connection->query(trim($sSQL));
$duration = microtime(true) - $start;
if ($log) {
$this->addQueryLog($sSQL, $duration);
}
if (!$result) {
//var_dump (debug_backtrace ());
//$data = debug_backtrace ();
//print_r ($data);
echo $sSQL;
throw new DbException('MySQL Error: ' . $this->connection->error);
} elseif ($result instanceof MySQLi_Result) {
return new Result($result);
}
// Insert ID will return zero if this query was not insert or update.
$this->insert_id = intval($this->connection->insert_id);
// Affected rows
$this->affected_rows = intval($this->connection->affected_rows);
if ($this->insert_id > 0) {
return $this->insert_id;
}
if ($this->affected_rows > 0) {
return $this->affected_rows;
}
return $result;
}
示例6: query
/**
* Performs a query on the database
*
* @param string $query
* @param int $resultmode
* @throws MySQLi\QueryException
* @return bool
*/
public function query($query, $resultmode = \MYSQLI_STORE_RESULT)
{
if (($result = parent::query($query, $resultmode)) === false) {
throw new \mysqli_sql_exception($this->error);
}
return $result;
}
示例7: fetchRelatedObjectRefsOfEntity
public function fetchRelatedObjectRefsOfEntity(MySQLi $mySQLi, ObjectEntity $otherEntity, QueryContext $queryContext, Scope $scope, array &$fetchedObjectRefs)
{
// Find the corresponding relationship, ignoring link-relationships.
$hasTerminatedObjects = FALSE;
foreach ($this->objectEntity->getRelationships() as $relationship) {
if ($relationship->getOppositeEntity($this->objectEntity) != $otherEntity) {
continue;
}
// Select the id of the related object.
$objectIdColumnName = $otherEntity->getObjectIdColumnName();
$query = new QueryRelatedEntity($this->objectEntity, $this->id, $relationship, $queryContext, $scope);
$query->setPropertyNames(array($objectIdColumnName));
$queryString = $query->getQueryString();
$queryResult = $mySQLi->query($queryString);
if (!$queryResult) {
throw new Exception("Error fetching ObjectRefs of entity '" . $otherEntity->getName() . "', associated to '" . $this->objectEntity->getName() . "[{$this->id}]' - " . $mySQLi->error . "\n<!--\n{$queryString}\n-->");
}
while ($dbObject = $queryResult->fetch_assoc()) {
$objectRef = new ObjectRef($otherEntity, $dbObject[$objectIdColumnName]);
if (!$queryContext->getParameterPublished() and isset($dbObject[QueryEntity::ID_TERMINATED])) {
$hasTerminatedObjects = TRUE;
} else {
// Always use the objectRef if we're fetching published data or if it's not terminated.
$fetchedObjectRefs[] = $objectRef;
}
}
$queryResult->close();
}
return $hasTerminatedObjects;
}
示例8: getServerVersion
public function getServerVersion()
{
$res = $this->dbcon->query("SELECT version() AS `version`");
if (!$res || $res->num_rows == 0) {
return '[not connected]';
}
$row = $res->fetch_assoc();
return $row['version'];
}
示例9: query
/**
* Executes a query which returns rows. Use it with SELECT statements.
* @param string $query
* @return DatabaseResult|bool
*/
public function query($query)
{
$this->lastQuery = $query;
$result = parent::query($query);
if ($result) {
return is_bool($result) ? $result : new DatabaseResult($result);
}
return FALSE;
}
示例10: evaluate
function evaluate($stu_answers, $studentid, $quizid)
{
// $myo = new MySQL();
$some = new MySQLi('localhost', 'root', 'root', 'codefundo');
$res = $some->query("SELECT * FROM answers") or die('fatal');
$res2 = $some->query("SELECT * FROM marks") or die('fatal');
// print_r($res2);
$result = array();
$marks = array();
if ($res) {
while ($s = $res->fetch_object()) {
foreach ($s as $key => $value) {
if ($s->{$key}) {
$result[$key] = $value;
}
}
}
}
if ($res2) {
while ($s = $res2->fetch_object()) {
foreach ($s as $key => $value) {
if ($s->{$key}) {
$marks[$key] = $value;
}
}
}
}
unset($result['quizid']);
$mark = 0;
foreach ($stu_answers as $quesid => $ans) {
if ($result[$quesid] == $ans) {
$mark += $marks[$quesid];
}
}
// var_dump($mark);
echo 'Score is:';
echo $mark;
echo '<Br><a href="dash.php">Continue-></a>';
if ($myo->Update($quizid, array('marks' => $mark), array('student_id' => $studentid))) {
print_r('Marks');
} else {
die('fatal');
}
}
示例11: query
/**
* Sends the query to Sphinx
* @param string $query The query string
* @return array The result array
* @throws Miaox_SphinxQl_Connection_Exception If the executed query produced an error
*/
public function query($query)
{
$this->connect();
$resource = $this->_driver->query($query);
if ($this->_driver->error) {
throw new Miaox_SphinxQl_Connection_Exception('[' . $this->_driver->errno . '] ' . $this->_driver->error . ' [ ' . $query . ']');
}
if ($resource instanceof mysqli_result) {
$rows = array();
while (!is_null($row = $resource->fetch_assoc())) {
$rows[] = $row;
}
$resource->free_result();
$result = $rows;
} else {
// sphinxql doesn't return insert_id because we always have to point it out ourselves!
$result = array($this->_driver->affected_rows);
}
return $result;
}
示例12: query
public function query($sql, $errorLevel = E_USER_ERROR)
{
$this->beforeQuery($sql);
// Benchmark query
$handle = $this->dbConn->query($sql, MYSQLI_STORE_RESULT);
if (!$handle || $this->dbConn->error) {
$this->databaseError($this->getLastError(), $errorLevel, $sql);
return null;
}
// Some non-select queries return true on success
return new MySQLQuery($this, $handle);
}
示例13: query
public function query($sql)
{
$resource = $this->link->query($sql);
if ($this->link->errno) {
trigger_error('Error: ' . $this->link->error . '<br />Error No: ' . $this->link->errno . '<br />' . $sql);
die;
}
if ($resource instanceof mysqli_result) {
$i = 0;
$data = array();
while ($result = $resource->fetch_assoc()) {
$data[$i] = $result;
$i++;
}
$resource->free();
$query = new stdClass();
$query->row = isset($data[0]) ? $data[0] : array();
$query->rows = $data;
$query->num_rows = $i;
unset($data);
return $query;
}
return $resource;
}
示例14: query
/**
* Execute a query and return a result object
*
* @param String $query The query to execute
* @return \r8\iface\DB\Adapter\Result
*/
public function query($query)
{
if (!isset($this->link)) {
$this->connect();
}
$result = $this->link->query($query);
if ($result === FALSE) {
throw new \r8\Exception\DB\Query($query, $this->link->error, $this->link->errno);
}
if (\r8\DB\Link::isSelect($query)) {
return new \r8\DB\Result\Read(new \r8\DB\MySQLi\Result($result), $query);
} else {
return new \r8\DB\Result\Write($this->link->affected_rows, $this->link->insert_id, $query);
}
}
示例15: create
/**
* Create a new annotation
*
* @param Struct\Annotation $annotation
* @return void
*/
public function create(Struct\Annotation $annotation)
{
$this->connection->query(sprintf('
INSERT INTO
`annotation`
VALUES (
null,
"%s",
%s,
%s,
"%s",
"%s",
"%s",
null
)', $this->connection->escape_string($annotation->file), (int) $annotation->line, (int) $annotation->character, $this->connection->escape_string($annotation->type), $this->connection->escape_string($annotation->class), $this->connection->escape_string($annotation->message)));
}