本文整理汇总了PHP中MySQLi类的典型用法代码示例。如果您正苦于以下问题:PHP MySQLi类的具体用法?PHP MySQLi怎么用?PHP MySQLi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MySQLi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: del_imgs
function del_imgs($kw)
{
if (strlen(trim($kw)) <= 0) {
return "";
}
$db = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($db->connect_error) {
return "";
}
echo "<table class='table'><tr><th class='text-center'>序号</th><th class='text-center'>删除文件</th>";
echo "<th class='text-center'><button class='btn btn-danger btn-xs' onclick='self_close();' >关闭</button></th></tr>";
$ps = explode(",", $kw);
$count = 0;
$res = null;
foreach ($ps as $p) {
if (strpos($p, "img/") !== 0) {
continue;
}
if (!file_exists($p)) {
continue;
}
$count++;
$sql = "delete from " . TB_PIC . " where url='" . $p . "'";
echo "<tr><td class='text-center'>{$count}</td><td>{$p}</td>";
$res = $db->prepare($sql);
$res->execute();
unlink($p);
if ($res) {
echo "<td class='text-center'>Success</td></tr>";
} else {
echo "<td class='text-center'>Fail</td></tr>";
}
}
echo "</table>";
}
示例2: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
$this->addToContainer('link', function ($c) {
$db_host = $this->getTestMySqlConnectionParam('host', 'localhost');
$db_port = $this->getTestMySqlConnectionParam('port', 3306);
$db_user = $this->getTestMySqlConnectionParam('user', 'root');
$db_pass = $this->getTestMySqlConnectionParam('pass', '');
$db_name = $this->getTestMySqlConnectionParam('database', $this->getTestMySqlDatabaseName($c['app_name']));
$link = new \MySQLi("{$db_host}:{$db_port}", $db_user, $db_pass);
if ($link->connect_error) {
throw new RuntimeException('Failed to connect to database. MySQL said: ' . $link->connect_error);
}
if (!$link->select_db($db_name)) {
throw new RuntimeException('Failed to select database');
}
return $link;
});
$this->addToContainer('connection', function ($c) {
$connection = new MysqliConnection($c['link']);
$connection->execute('SET foreign_key_checks = 0;');
foreach ($connection->getTableNames() as $table_name) {
$connection->dropTable($table_name);
}
$connection->execute('SET foreign_key_checks = 1;');
return $connection;
});
}
示例3: 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;
}
示例4: __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();
}
}
示例5: toSQL
/**
* Formats this object, escaping the values as needed.
*
* @param MySQLi $con the connection to use for escaping
*/
public function toSQL(\MySQLi $con)
{
$oper = null;
$val = "NULL";
if ($this->value === null) {
if ($this->operator == self::EQ) {
$oper = " is ";
} else {
$oper = " is not ";
}
} else {
$oper = $this->operator;
if ($this->value instanceof DBObject) {
$val = '"' . $con->real_escape_string($this->value->id) . '"';
} elseif ($this->value instanceof \DateTime) {
$val = '"' . $this->value->format('Y-m-d H:i:s') . '"';
} elseif ($this->value instanceof DBField) {
$val = $this->value->getName();
} else {
$val = '"' . $con->real_escape_string($this->value) . '"';
}
}
$field = $this->field;
if ($field instanceof DBField) {
$field = $field->getName();
}
return '(' . $field . $oper . $val . ')';
}
示例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: createDatabase
static function createDatabase($db = 'mysqli')
{
if ($db === 'MySQLi') {
$db = MySQLi::getInstance();
} else {
$db = MySQLi::getInstance();
}
return $db;
}
示例8: query
private static function query($sql)
{
if (self::$debug) {
tprintWarning($sql);
}
return self::$DB_CONN->query($sql);
}
示例9: __construct
public function __construct()
{
@parent::connect(NAMESERVER, USERDB, PASSWDB, NAMEDB);
if ($this->connect_errno) {
throw new Exception(date('d/m/Y G:i:s T') . " Error#:" . $this->connect_errno . " [ " . $this->connect_error . " ]");
}
}
示例10: 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;
}
}
示例11: __construct
public function __construct()
{
// inhibit subclassing and instantiation from outside
require_once 'pwd.php';
// read account data (including password)
// initialize the transient associative array
$this->modelTransient = array();
// initialize new or open existing session
session_name($config['session']);
session_start();
// connect to database
try {
parent::__construct($config['host'], $config['user'], $config['pwd'], "ewa");
// check connection
if (mysqli_connect_error()) {
// $this is invalid in case of error
throw new Exception("Keine Verbindung zur Datenbank: " . mysqli_connect_error());
}
} catch (Exception $e) {
// do not show the password in an error message
throw new Exception(str_replace($config['pwd'], "xxx", $e->getMessage()));
}
// define character encoding for connection to database
if (!$this->set_charset(self::charsetDB)) {
throw new Exception("Fehler beim Laden des Zeichensatzes " . self::charsetDB . ": " . $this->error);
}
}
示例12: 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;
}
示例13: close
/**
* Fecha a conexão com o banco de dados.
*
* @return void
*/
public function close()
{
if ($this->isConnected()) {
$this->connection->close();
unset($this->connection);
$this->connection = null;
}
}
示例14:
function __construct()
{
self::$host = Config::get('db_host');
self::$db = Config::get('db_name');
self::$user = Config::get('db_user');
self::$password = Config::get('db_pass');
parent::__construct(self::$host, self::$user, self::$password, self::$db);
}
示例15: escape
public function escape($txt)
{
if (is_array($txt)) {
throw new Error('Invalid parameter: escape cannot handle arrays.');
}
$this->connect();
return $this->connection->real_escape_string($txt);
}