本文整理汇总了PHP中resource::query方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::query方法的具体用法?PHP resource::query怎么用?PHP resource::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: select
public function select($sql)
{
$result = $this->pdo->query($sql);
$result->setFetchMode(\PDO::FETCH_ASSOC);
$data = $result->fetchAll();
return $data;
}
示例2: connect
/**
* Connect to database
* @param string $databaseName
*/
public function connect($databaseName = "")
{
$this->bdLink = @mysqli_connect($this->hostname, $this->username, $this->password, '', $this->port);
$this->gestionErreur(!$this->bdLink, 'Connect - ' . self::ERROR_CONNECT . ' ' . $this->hostname);
if ($databaseName != "") {
$this->selectBd($databaseName);
}
//request with UTF-8 character set according to http://se.php.net/manual/en/function.mysqli-query.php
$this->bdLink->query("SET NAMES 'utf8'");
}
示例3: _connect
/**
* Creates a connection to the database.
*/
protected function _connect()
{
if ($this->connection) {
return;
}
$this->connection = new PDO($this->_dsn(), $this->cfg->user, $this->cfg->pass, $this->cfg->driverOptions);
foreach ($this->cfg->conQuery as $q) {
$this->connection->query($q);
}
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
示例4: query
/**
* Executes an SQL query, returning an SQLiteResult object if the query
* returns results.
*
* @param string $sql The SQL query to execute.
* @param int $resultType Controls how the row(s) will be returned.
*
* @return mixed Returns a SQLiteResult object, or false on failure.
*
* @throws SQLiteException on failure.
*/
public function query($sql, $resultType = SQLiteResult::RESULT_OBJ)
{
try {
$result = $this->link->query($sql);
if ($result !== false) {
return new SQLiteResult($result, $resultType);
}
} catch (PDOException $e) {
throw new SQLiteException($e->getMessage());
}
return false;
}
示例5: array
/**
* データベースの一覧を配列で取得する
* @return array
*/
function _getTables()
{
$tables = array();
switch ($this->_dbType) {
case 'mysql':
$rs = mysql_query("SHOW TABLES;", $this->_dbLink);
while ($table = mysql_fetch_row($rs)) {
$tables[] = $table[0];
}
break;
case 'postgres':
$tables = $this->pg_list_tables($this->_dbLink);
break;
case 'sqlite':
// TODO 未実装
break;
case 'sqlite3':
$sth = $this->_dbLink->query("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
$result = $sth->fetchAll();
foreach ($result as $table) {
$tables[] = $table[0];
}
break;
}
return $tables;
}
示例6: query
/**
* Send Query to the database
* @param string $sql
* @return resource
*/
public function query($sql = null)
{
$sql = str_replace("{PREFIX}", $this->configs['mysql']['prefix'], $sql);
if (empty($sql)) {
return false;
}
if ($this->auto_free) {
$this->freeResult();
}
if ($this->db_type == "mysqli") {
$this->query_id = $this->link_id->query($sql);
if ($this->link_id->error != "") {
$this->halt($this->link_id->error);
}
} else {
if ($this->db_type == "mysql") {
$this->query_id = mysql_query($sql, $this->link_id) or $this->halt(mysql_error());
}
}
if (!$this->query_id) {
if ($this->db_type == "mysqli") {
$this->errno = $this->link_id->errno;
$this->error = $this->link_id->error;
} else {
if ($this->db_type == "mysql") {
$this->errno = mysql_errno($this->link_id);
$this->error = mysql_error($this->link_id);
}
}
$this->halt("Invalid SQL: " . $sql);
}
return $this->query_id;
}
示例7: query
/**
*
* @param type $sql
* @param bool $useExceptions Optional - If set to TRUE will throw an _Exception() | If set to FALSE will return FALSE on error
* @return boolean|string
* @throws _Exception with code _DB_QUERY_ERROR only if _DB_USE_EXCEPTIONS == TRUE or $useExceptions (override) == TRUE
*/
public function query($sql, $useExceptions = _DbConfig::USE_EXCEPTIONS)
{
if (!$this->isConnected) {
$rc = $this->createConnection();
if ($rc === FALSE) {
return FALSE;
}
}
if (_DbConfig::LOG_SQL) {
_Log::debug($sql);
}
try {
$this->lastResult = $this->mysqli->query($sql);
} catch (Exception $e) {
if ($useExceptions) {
throw new _Exception('Error executing query | ' . $e->getMessage(), _DbErrors::QUERY_ERROR, $e);
} else {
return FALSE;
}
}
if ($this->lastResult === FALSE) {
// Error occurred
_Log::crit('Error occurred while executing query');
if ($useExceptions) {
throw new _Exception('Error executing query', _DbErrors::QUERY_ERROR);
} else {
return FALSE;
}
}
$this->lastCount = $this->mysqli->affected_rows;
return $this->lastResult;
}
示例8: execute
/**
* Executes an SQL script on the connection
* @param string $sql SQL script
* @return zibo\library\database\mysql\MysqlResult Result object
* @throws zibo\library\database\mysql\exception\MysqlException when the provided SQL is empty
* @throws zibo\library\database\mysql\exception\MysqlException when not connected to the database
* @throws zibo\library\database\mysql\exception\MysqlErrorException when the SQL could not be executed
*/
public function execute($sql)
{
if (String::isEmpty($sql)) {
throw new SqliteException('Provided SQL is empty');
}
if (!$this->isConnected()) {
$exception = new SqliteException('Not connected to the database');
Zibo::getInstance()->runEvent('log', 'Execute ' . $sql, $exception->getMessage(), 1, DatabaseManager::LOG_NAME);
throw $exception;
}
try {
$resultResource = $this->connection->query($sql);
if ($resultResource === false) {
$errorCode = $this->connection->lastErrorCode();
$errorMessage = $this->connection->lastErrorMessage();
$exception = new SqliteErrorException($errorCode, $errorMessage);
Zibo::getInstance()->runEvent('log', 'Execute ' . $sql, $exception->getMessage(), 1, DatabaseManager::LOG_NAME);
throw $exception;
}
} catch (Exception $exception) {
Zibo::getInstance()->runEvent('log', 'Execute ' . $sql, $exception->getMessage(), 1, DatabaseManager::LOG_NAME);
throw $exception;
}
Zibo::getInstance()->runEvent('log', 'Execute ' . $sql, '', 0, DatabaseManager::LOG_NAME);
$result = new SqliteResult($sql, $resultResource);
if ($resultResource !== true) {
$resultResource->finalize();
}
return $result;
}
示例9: addItems
/**
* Add items on the database
*
* @param Integer $feed_id ToDo desc
* @param Array $items ToDo desc
*
* @return void
*/
public function addItems($feed_id, $items)
{
if (empty($items)) {
return;
}
$items = array_slice($items, 0, intval($this->getConfig('FeedTicker.itemsLimit', 5)));
$dli = intval($this->getConfig('FeedTicker.dateLimit', 60 * 60 * 24 * 7));
$dateLimit = time() - $dli;
$q = $this->db->prepare('INSERT INTO ft_items (
feed_id, updated, title, link, author, read
) VALUES (
:feed_id, :updated, :title, :link, :author, :read
)');
foreach ($items as $i) {
if (!empty($i['updated']) and $i['updated'] < $dateLimit) {
continue;
}
// Check if this item already exists
$sql = 'SELECT COUNT(*) FROM ft_items WHERE feed_id = ' . $this->db->quote($feed_id) . ' AND link = ' . $this->db->quote(trim($i['link']));
$opa = $this->db->query($sql)->fetchColumn();
if ((bool) $this->db->query($sql)->fetchColumn()) {
continue;
}
$q->execute(array(':feed_id' => $feed_id, ':updated' => trim($i['updated']), ':title' => trim($i['title']), ':link' => trim($i['link']), ':author' => trim($i['author']), ':read' => 0));
}
}
示例10: queryF
/**
* perform a query on the database
*
* @param string $sql a valid MySQL query
* @param int $limit number of records to return
* @param int $start offset of first record to return
*
* @return bool|resource query result or FALSE if successful
* or TRUE if successful and no result
* @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector.
*/
public function queryF($sql, $limit = 0, $start = 0)
{
$this->deprecated();
if (!empty($limit)) {
if (empty($start)) {
$start = 0;
}
$sql = $sql . ' LIMIT ' . (int) $start . ', ' . (int) $limit;
}
$xoopsPreload = XoopsPreload::getInstance();
$xoopsPreload->triggerEvent('core.database.query.start');
try {
$result = $this->conn->query($sql);
} catch (Exception $e) {
$result = false;
}
$this->lastResult = $result;
$xoopsPreload->triggerEvent('core.database.query.end');
if ($result) {
$xoopsPreload->triggerEvent('core.database.query.success', array($sql));
return $result;
} else {
$xoopsPreload->triggerEvent('core.database.query.failure', array($sql, $this));
return false;
}
}
示例11: exec
/**
* {@inheritDoc}
*
* @param string $sql SQL statement to execute
* @param array $params bind_name => value values to interpolate into
* the $sql to be executes
* @return mixed false if query fails, resource or true otherwise
*/
function exec($sql, $params = array())
{
static $last_sql = NULL;
static $statement = NULL;
$is_select = strtoupper(substr(ltrim($sql), 0, 6)) == "SELECT";
if ($last_sql != $sql) {
$statement = NULL;
//garbage collect so don't sqlite lock
}
if ($params) {
if (!$statement) {
$statement = $this->pdo->prepare($sql);
}
$result = $statement->execute($params);
$this->num_affected = $statement->rowCount();
if ($result) {
if ($is_select) {
$result = $statement;
} else {
$result = $this->num_affected;
}
}
} else {
if ($is_select) {
$result = $this->pdo->query($sql);
$this->num_affected = 0;
} else {
$this->num_affected = $this->pdo->exec($sql);
$result = $this->num_affected + 1;
}
}
$last_sql = $sql;
return $result;
}
示例12: query
/**
* Execute a MySQL-Query
*
* @throws Exception
* @param string $query The query to execute
* @param const $kind Type of result set
*
* @return array
*/
public function query($query, $kind = self::ARRAY_OBJECT)
{
if (!$this->_mysqli instanceof mysqli) {
$this->dbConnect($this->dbSelected);
}
//echo "<br>Mysqli: executing query: " . $query;
$result = $this->_mysqli->query($query);
if (false === $result) {
$this->sqlError($this->_mysqli->error, $this->_mysqli->errno);
}
if (!$result instanceof mysqli_result || $kind === self::SIMPLE) {
return $result;
}
$ret = array();
if ($kind === self::ARRAY_OBJECT) {
while ($row = $result->fetch_object()) {
$ret[] = $row;
}
} elseif ($kind === self::ARRAY_NUMERIC) {
while ($row = $result->fetch_array(MYSQLI_NUM)) {
$ret[] = $row;
}
} elseif ($kind === self::ARRAY_ASSOC) {
while ($row = $result->fetch_assoc()) {
$ret[] = $row;
}
}
if ($result instanceof mysqli) {
$result->close();
}
return $ret;
}
示例13: __construct
/**
* Construct
*
* @param Registry $registry
* @param Request $request
* @param int $language_id Default language id
*/
public function __construct(Registry $registry, Request $request, $language_id)
{
$_translation = array();
$this->_db = $registry->get('db');
try {
$statement = $this->_db->query('SELECT * FROM `language`');
} catch (PDOException $e) {
if ($this->_db->inTransaction()) {
$this->_db->rollBack();
}
trigger_error($e->getMessage());
}
if ($statement->rowCount()) {
foreach ($statement->fetchAll() as $language) {
// Add languages registry
$this->_languages[$language->language_id] = array('language_id' => $language->language_id, 'language_code' => $language->code, 'language_locale' => $language->locale, 'language_name' => $language->name);
// Set default language
if ($language->language_id == $language_id) {
$this->_language_id = $language->language_id;
$this->_language_code = $language->code;
$this->_language_locale = $language->locale;
$this->_language_name = $language->name;
}
// Get active language
if (isset($request->get['language_id'])) {
$_language_id = (int) $request->get['language_id'];
} else {
if (isset($request->cookie['language_id'])) {
$_language_id = (int) $request->cookie['language_id'];
} else {
$_language_id = (int) DEFAULT_LANGUAGE_ID;
}
}
// Set current language
$language_file = DIR_BASE . 'language' . DIR_SEPARATOR . $language->code . '.php';
if ($_language_id == $language->language_id && file_exists($language_file) && is_readable($language_file)) {
$this->_language_id = $language->language_id;
$this->_language_code = $language->code;
$this->_language_locale = $language->locale;
$this->_language_name = $language->name;
// Load language package if exist
require_once $language_file;
$this->_translation = $_translation;
}
}
}
}
示例14: execQuery
/**
* Ejecuta la consulta SQL expresada en la variable _sqlQuery.
* @method execQuery()
* @access public
* @return resorce|boolean|null
* @throws Exception
* @see self::_throwModelException(), self::isValidConnResource(), self::_parseResults()
*/
public function execQuery()
{
if (!empty($this->_sqlQuery) && !is_string($this->_sqlQuery)) {
exit('$sql no es una consulta valida.');
}
$this->_resource = $this->_PDOmySQLConn->query($this->_sqlQuery);
$this->_parseResults();
}
示例15: query
/**
* query
* @param string $sql
* @param resource $connResource
* @return array
*/
public function query($sql, $connResource)
{
$rows = array();
$result = $connResource->query($sql);
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}