本文整理汇总了PHP中mysqli::mysqli方法的典型用法代码示例。如果您正苦于以下问题:PHP mysqli::mysqli方法的具体用法?PHP mysqli::mysqli怎么用?PHP mysqli::mysqli使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysqli
的用法示例。
在下文中一共展示了mysqli::mysqli方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Creates the Database object and sets the database connection info based on
* the config file.
*
* You can connect to another database on the server listed in the config class by passing its
* name in the constructor
*
* Only supports Mysql databases.
*
* @see includes/walleye.config.php
* @param string $db
*/
private function __construct($db = null)
{
$dbOptions = Walleye::getInstance()->getDbOptions();
$server = $dbOptions['SERVER'];
$user = $dbOptions['USER'];
$password = $dbOptions['PASS'];
$port = $dbOptions['PORT'];
if (is_null($db)) {
$database = $dbOptions['DATABASE'];
} else {
$database = $db;
}
parent::mysqli($server, $user, $password, $database, $port);
}
示例2: __construct
/**
* Creates a mysqli instance representing a connection to a database
*
* @author Basilio Briceno <bbh@tlalokes.org>
* @param array $dsn An array with DSN information
* @return mysqli Returns a mysqli object on success
*/
public function __construct(array &$dsn)
{
$conn = parent::mysqli($dsn['host'], $dsn['username'], $dsn['password'], $dsn['name']);
if (mysqli_connect_errno($this)) {
throw new Exception("Failed to connect: " . mysqli_connect_error());
}
return $conn;
}
示例3: mysqli
require_once "../vendor/autoload.php";
use Configuration\Configuration;
error_reporting(0);
echo "\n<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n<meta name='viewport' content='width=device-width'/>\n<title>Login & Signup Kit Database Installation</title>\n</head>\n\n<body>\n<h1>Login & Signup Kit Database Installation</h1>\n";
if (isset($_GET["install"])) {
$dbPassword = Configuration::DATABASE_PASSWORD;
$dbUser = Configuration::DATABASE_USER;
$dbHost = Configuration::DATABASE_HOST;
$dbPort = Configuration::DATABASE_PORT;
$dbDatabase = Configuration::DATABASE_NAME;
$dbDatabasePrefix = Configuration::DATABASE_PREFIX;
$completeDatabaseName = $dbDatabasePrefix . $dbDatabase;
$dbInstall = false;
$mysqli = new mysqli();
$mysqli->mysqli($dbHost, $dbUser, $dbPassword, $completeDatabaseName, $dbPort);
if ($mysqli->connect_error) {
$cfg_result = "<p>Cant connect to MySQL server. Check MySQL configuration file (DbConnection.php)</p>";
} else {
$databaseCreate = "\n CREATE DATABASE IF NOT EXISTS " . $completeDatabaseName . " DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;\n ";
$loginAttempts = "\n\t CREATE TABLE IF NOT EXISTS login_attempts (\n user_id int(11) NOT NULL,\n time varchar(30) NOT NULL,\n attemp_id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n time_stamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP\n ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;\n\t ";
$membersTable = "\n CREATE TABLE IF NOT EXISTS members (\n id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n username varchar(30) NOT NULL,\n email varchar(50) NOT NULL,\n password char(128) NOT NULL\n ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;\n\t ";
$password = '$2y$15$BTm77jO53MqbZXHNCHBtsujee0BcaqLPOQTVtILGlDfhOHKEmJmzW';
$membersData = "\n INSERT INTO members (username, email, password) VALUES\n ('test', 'test@test.com','" . $password . "');\n ";
$passwordRequest = "\n CREATE TABLE IF NOT EXISTS password_requests (\n id_request int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n user_email varchar(50) NOT NULL,\n time_stamp varchar(100) NOT NULL,\n token varchar(150) NOT NULL\n ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n\n ";
echo '<h2>Installer Log:</h2>';
$stmt = $mysqli->prepare($databaseCreate);
if ($stmt->execute()) {
$cfg_result = "<p style='color: green'>New " . $completeDatabaseName . " database created successfully</p>";
} else {
$cfg_result = "<p>Error creating " . $completeDatabaseName . " database</p>";
示例4:
function __construct()
{
parent::mysqli(DBHOST, DBUSERNAME, DBPASSWORD, DBNAME);
}