mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-05-15 04:27:34 +08:00
101 lines
2.2 KiB
PHP
101 lines
2.2 KiB
PHP
<?php
|
|
namespace Nexus\Database;
|
|
|
|
/**
|
|
* @deprecated
|
|
*
|
|
* use DBPdo instead
|
|
*/
|
|
class DBMysqli implements DBInterface
|
|
{
|
|
private $mysqli;
|
|
|
|
public function connect($host, $username, $password, $database, $port, $driver = 'mysql')
|
|
{
|
|
$mysqli = new \mysqli($host, $username, $password, $database, $port);
|
|
/* check connection */
|
|
if (mysqli_connect_errno()) {
|
|
throw new DatabaseException(mysqli_connect_error());
|
|
}
|
|
$mysqli->set_charset("utf8mb4");
|
|
$mysqli->query("SET collation_connection = 'utf8mb4_unicode_ci'");
|
|
$mysqli->query("SET sql_mode=''");
|
|
$mysqli->query("SET time_zone='".date('P')."'");
|
|
|
|
/* activate reporting */
|
|
$driver = new \mysqli_driver();
|
|
$driver->report_mode = MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX;
|
|
|
|
return $this->mysqli = $mysqli;
|
|
}
|
|
|
|
public function query(string $sql)
|
|
{
|
|
return $this->mysqli->query($sql);
|
|
}
|
|
|
|
public function error(): string
|
|
{
|
|
return $this->mysqli->error;
|
|
}
|
|
|
|
public function errno(): int
|
|
{
|
|
return $this->mysqli->errno;
|
|
}
|
|
|
|
public function numRows($mysqliResult): int
|
|
{
|
|
return $mysqliResult->num_rows;
|
|
}
|
|
|
|
public function selectDb($database)
|
|
{
|
|
return $this->mysqli->select_db($database);
|
|
}
|
|
|
|
public function fetchAssoc($mysqliResult)
|
|
{
|
|
return $mysqliResult->fetch_assoc();
|
|
}
|
|
|
|
public function fetchRow($mysqliResult)
|
|
{
|
|
return $mysqliResult->fetch_row();
|
|
}
|
|
|
|
public function fetchArray($mysqliResult, $type)
|
|
{
|
|
if (is_null($type)) {
|
|
$type = MYSQLI_BOTH;
|
|
}
|
|
return $mysqliResult->fetch_array($type);
|
|
}
|
|
|
|
public function affectedRows(): int
|
|
{
|
|
return $this->mysqli->affected_rows;
|
|
}
|
|
|
|
public function escapeString(string $string): string
|
|
{
|
|
return $this->mysqli->real_escape_string($string);
|
|
}
|
|
|
|
public function lastInsertId(): int
|
|
{
|
|
return $this->mysqli->insert_id;
|
|
}
|
|
|
|
public function freeResult($mysqliResult)
|
|
{
|
|
return $mysqliResult->free_result();
|
|
}
|
|
|
|
public function prepare(string $sql): \PDOStatement
|
|
{
|
|
throw new \RuntimeException("mysqli not supported");
|
|
}
|
|
|
|
}
|