本文整理汇总了PHP中mysqli_select_db函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_select_db函数的具体用法?PHP mysqli_select_db怎么用?PHP mysqli_select_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysqli_select_db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wechatFlow
public function wechatFlow()
{
$this->conn = new mysqli("localhost", USER, PASSWORD);
//连接MySql
if ($this->conn->connect_errno) {
die("Connect Error(" . $this->conn->connect_errno . ")" . $this->conn->connect_error);
}
$this->conn->query("SET NAMES UTF8");
$this->conn->query("CREATE DATABASE IF NOT EXISTS " . DATABASE . " DEFAULT CHARACTER SET UTF8");
//创建数据库
mysqli_select_db($this->conn, DATABASE);
//选择数据库
$this->conn->query("CREATE TABLE IF NOT EXISTS rel_manager(\r\n\t\t\tid int not null primary key auto_increment,\r\n\t\t\tmanager_name LONGTEXT CHARACTER SET UTF8,\r\n\t\t\tmanager_password LONGTEXT CHARACTER SET UTF8,\r\n\t\t\tcomment LONGTEXT CHARACTER SET UTF8\r\n\t\t)");
//创建管理员表
// $value=mysql_query("SELECT * FROM rel_manager");
// //if(!$row=mysql_fetch_array($value)){//如果超级管理员不存在
// $manager_password="123456";
// $password=md5($manager_password);
// mysql_query(" INSERT INTO rel_manager (manager_name,manager_password,A_Group_ID,comment)
// VALUES ('manager','".$password."','1','超级管理员')");
// //}//插入超级管理员
$this->conn->query("CREATE TABLE IF NOT EXISTS rel_alg (\r\n\t\t\tid int not null primary key auto_increment,\r\n\t\t\talg_name LONGTEXT CHARACTER SET UTF8\r\n\t\t)");
//创建算法表
$this->conn->query("CREATE TABLE IF NOT EXISTS rel_process (\r\n\t\t\tid int not null primary key auto_increment\r\n\t\t)");
//创建生命周期过程表
$this->conn->query("CREATE TABLE IF NOT EXISTS rel_tech (\r\n\t\t\tid int not null primary key auto_increment\r\n\t\t)");
//创建技术措施表
}
示例2: display_view
function display_view()
{
$con = mysqli_connect('localhost', 'root', '');
$db = mysqli_select_db($con, 'stats');
$query = "SELECT s.Year, t.team_name FROM season s, team t where s.winner_team_id = t.team_id";
$result = mysqli_query($con, $query);
if ($result) {
$row = mysqli_fetch_row($result);
echo '<table border="1" style= "text-align: center; color: #092f44; margin: 0 auto;" >';
echo '<tr> <th>Season Year</th>
<th>Winner Team</th>
</tr>';
while ($row) {
$col = count($row);
echo "<tr>";
for ($c = 0; $c < $col; $c++) {
echo "<td>" . $row[$c] . "</td>";
}
echo "</tr>";
$row = mysqli_fetch_row($result);
}
echo "</table>";
} else {
echo "err";
}
}
示例3: connect
function connect($server, $db, $user, $password, $socketPath, $charset = null, $port = false)
{
$connection = false;
if ($socketPath !== false) {
ini_set("mysqli.default_socket", $socketPath);
}
if ($this->UsePersistentConnection == true) {
// Only supported on PHP 5.3 (mysqlnd)
if (version_compare(PHP_VERSION, '5.3') > 0) {
$this->Server = 'p:' . $this->Server;
} else {
eZDebug::writeWarning('mysqli only supports persistent connections when using php 5.3 and higher', 'eZMySQLiDB::connect');
}
}
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$connection = mysqli_connect($server, $user, $password, null, (int) $port, $socketPath);
$dbErrorText = mysqli_connect_error();
eZPerfLogger::accumulatorStop('mysqli_connection');
$maxAttempts = $this->connectRetryCount();
$waitTime = $this->connectRetryWaitTime();
$numAttempts = 1;
while (!$connection && $numAttempts <= $maxAttempts) {
sleep($waitTime);
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$connection = mysqli_connect($this->Server, $this->User, $this->Password, null, (int) $this->Port, $this->SocketPath);
eZPerfLogger::accumulatorStop('mysqli_connection');
$numAttempts++;
}
$this->setError();
$this->IsConnected = true;
if (!$connection) {
eZDebug::writeError("Connection error: Couldn't connect to database. Please try again later or inform the system administrator.\n{$dbErrorText}", __CLASS__);
$this->IsConnected = false;
throw new eZDBNoConnectionException($server);
}
if ($this->IsConnected && $db != null) {
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$ret = mysqli_select_db($connection, $db);
eZPerfLogger::accumulatorStop('mysqli_connection');
if (!$ret) {
//$this->setError();
eZDebug::writeError("Connection error: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
$this->IsConnected = false;
}
}
if ($charset !== null) {
$originalCharset = $charset;
$charset = eZCharsetInfo::realCharsetCode($charset);
}
if ($this->IsConnected and $charset !== null) {
eZPerfLogger::accumulatorStart('mysqli_connection', 'mysqli_total', 'Database connection');
$status = mysqli_set_charset($connection, eZMySQLCharset::mapTo($charset));
eZPerfLogger::accumulatorStop('mysqli_connection');
if (!$status) {
$this->setError();
eZDebug::writeWarning("Connection warning: " . mysqli_errno($connection) . ": " . mysqli_error($connection), "eZMySQLiDB");
}
}
return $connection;
}
示例4: connect
public function connect()
{
if ($this->conn_id && $this->state == self::OPEN) {
mysqli_select_db($this->conn_id, $this->getDatabase());
return true;
}
//TODO preConnect actions should be called from here
$hostString = $this->getHost();
if ($this->getPort() != '') {
$hostString .= ':' . $this->getPort();
}
if (isset($this->options['socket']) && $this->options['socket'] != '') {
$hostString .= ':' . $this->options['socket'];
}
$flags = isset($this->options['flags']) ? $this->options['flags'] : null;
if (isset($this->options['persistent']) && $this->options['persistent'] == true) {
$this->conn_id = @mysqli_pconnect($hostString, $this->getUser(), $this->getPassword(), $flags);
} else {
$this->conn_id = @mysqli_connect($hostString, $this->getUser(), $this->getPassword(), $flags);
}
if (!$this->conn_id) {
$this->state = self::CLOSED;
$msg = '[!Database connection error!]: ' . $this->getDatabase() . ' - ' . $this->getErrorMsg();
PhpBURN_Message::output($msg, PhpBURN_Message::ERROR);
return false;
}
//Selecting database
mysqli_select_db($this->conn_id, $this->getDatabase());
$this->state = self::OPEN;
//TODO onConnectSucess actions should be called from here
return true;
}
示例5: _getDb
/**
* 指定 mcString 得到对应的 memcache 对象
*
* @param string $mcString
* @return memcache
*/
private function _getDb($dbString)
{
$dbConfig = new Yaf_Config_Ini(APPLICATION_PATH . '/conf/database.ini', YAF_ENVIRON);
if (!$dbConfig instanceof Yaf_Config_Ini) {
exit("db system err");
}
if (!$dbConfig->database->get($dbString)) {
exit("no dbstring: " . $dbString);
}
if (!isset(self::$_dbPool[$dbString])) {
$link = mysqli_connect($dbConfig->database->get($dbString)->host, $dbConfig->database->get($dbString)->username, $dbConfig->database->get($dbString)->password, '', $dbConfig->database->get($dbString)->port);
if (!$link) {
logLib::errorModuleLog($dbString);
return false;
}
$this->_db = $link;
$this->_dbKey = '';
self::$_dbPool[$dbString] = $link;
} else {
$this->_db = self::$_dbPool[$dbString];
}
if ($this->_dbKey != $dbString) {
// mysql_select_db($dbconfig['dbname'], $this->_db);
mysqli_select_db($this->_db, $dbConfig->database->get($dbString)->dbname);
$this->_dbKey = $dbString;
}
return true;
}
示例6: get_data
public function get_data()
{
$con = mysqli_connect("localhost", "MaxMelnyk", "781227maks") or die("Something wrong...");
mysqli_select_db($con, "tour_firm") or die(mysql_error());
mysqli_query($con, 'SET NAMES utf8');
$query = "SELECT * FROM tours WHERE ID = " . $_GET['id'];
$res = mysqli_query($con, $query) or die(mysql_error());
$data['tour'] = mysqli_fetch_array($res);
$query = "SELECT * FROM cities WHERE tourID = " . $data['tour']['ID'] . " ORDER BY starttime";
$res = mysqli_query($con, $query) or die(mysql_error());
$num_cities = $res->num_rows;
foreach ($res as $row) {
$data['cities'][] = $row;
}
for ($i = 0; $i < $num_cities; $i++) {
$query = "SELECT * FROM excursions WHERE cityID = " . $data['cities'][$i]['ID'] . " ORDER BY starttime";
$res = mysqli_query($con, $query) or die(mysql_error());
foreach ($res as $row) {
$data['cities'][$i]['excursions'][] = $row;
}
$query = "SELECT * FROM accommodation WHERE cityID = " . $data['cities'][$i]['ID'];
$res = mysqli_query($con, $query) or die(mysql_error());
$data['cities'][$i]['accommodation'] = mysqli_fetch_array($res);
if ($i != $num_cities - 1) {
$query = "SELECT * FROM transfers WHERE startcityID = " . $data['cities'][$i]['ID'] . " AND finishcityID = " . $data['cities'][$i + 1]['ID'] . " AND tourID = " . $data['tour']['ID'];
$res = mysqli_query($con, $query) or die(mysql_error());
$data['transfers'][] = mysqli_fetch_array($res);
}
}
return $data;
}
示例7: connect
function connect($db_type, $var1 = false, $var2 = false, $var3 = false, $var4 = false, $var5 = '')
{
global $db_connected, $mysql_connect, $mysql_select_db, $sqlite_open, $db_type1, $db_prefix;
$db_type1 = $db_type;
$db_prefix = $var5;
switch ($db_type) {
case 'mysql':
#var1 = db_host | var2 = db_user | var3 = db_pass | var4 = db_name | var5 = db_prefix
$mysql_connect = mysql_connect($var1, $var2, $var3) or die("ERROR: 001");
if ($mysql_connect) {
mysql_select_db($var4, $mysql_connect) or die("ERROR: 002");
mysql_query("SET NAMES 'utf8'");
$db_connected = true;
}
break;
case 'mysqli':
#var1 = db_host | var2 = db_user | var3 = db_pass | var4 = db_name | var5 = db_prefix
$mysql_connect = mysqli_connect($var1, $var2, $var3, $var4) or die("ERROR: 001");
if ($mysql_connect) {
mysqli_select_db($mysql_connect, $var4) or die("ERROR: 002");
mysqli_query($mysql_connect, "SET NAMES 'utf8'");
$db_connected = true;
}
break;
case 'sqlite':
#var1 = db_path
$sqlite_open = sqlite_open($var1, 0666, $sqlite_error) or die("ERROR: 003");
sqlite_query($sqlite_open, "SET NAMES 'utf8'");
if ($sqlite_open) {
$db_connected = true;
}
break;
}
}
示例8: display_view
function display_view()
{
$con = mysqli_connect('localhost', 'root', '');
$db = mysqli_select_db($con, 'stats');
$query = "SELECT team_name,(no_of_wins + no_of_losses+no_of_draws) as Total_Matches, no_of_wins,no_of_losses,no_of_draws FROM team order by Total_Matches desc";
$result = mysqli_query($con, $query);
if ($result) {
$row = mysqli_fetch_row($result);
echo '<table border="1" style= "text-align: center; color: #092f44; margin: 0 auto;" >';
echo '<tr> <th>Team </th>
<th>Matches Played</th>
<th>WON</th>
<th>LOST</th>
<th>DRAW</th>
</tr>';
while ($row) {
$col = count($row);
echo "<tr>";
for ($c = 0; $c < $col; $c++) {
echo "<td>" . $row[$c] . "</td>";
}
echo "</tr>";
$row = mysqli_fetch_row($result);
}
echo "</table>";
} else {
echo "err";
}
}
示例9: connect
/**
* Function to connect with database
*/
function connect()
{
// Connecting to mysql database
$this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
// Selecing database
$db = mysqli_select_db($this->connection, DB_DATABASE) or die(mysql_error()) or die(mysql_error());
}
示例10: dbConnect
private function dbConnect()
{
$this->obDb = mysqli_connect(self::DB_SERVER, self::DB_USER, self::DB_PASSWORD);
if ($this->obDb) {
mysqli_select_db($this->obDb, self::DB);
}
}
示例11: connect
function connect($db)
{
if ($db['port']) {
$db['server'] .= ':' . $port;
}
if ($this->link_identifier) {
$this->disconnect();
}
$this->link_identifier = $db['persistent'] ? @mysqli_pconnect($db['server'], $db['username'], $db['password']) : @mysqli_connect($db['server'], $db['username'], $db['password']);
if ($this->link_identifier) {
if (@mysqli_select_db($this->link_identifier, $db['database'])) {
mysqli_query($this->link_identifier, 'SET NAMES utf8');
//mysqli_query($this->link_identifier, 'SET character_set_results = NULL');
return $this->link_identifier;
}
$error = '<center>There is currently a problem with the site<br/>Please try again later<br /><br />Error Code: DB2</center>';
}
if (!$this->report_error) {
return false;
}
if (!isset($error)) {
$error = '<center>There is currently a problem with the site<br/>Please try again later<br /><br />Error Code: DB1</center>';
}
$this->disconnect();
trigger_error($error, E_USER_ERROR);
die;
}
示例12: createHR
public function createHR($selectedName)
{
//$conn = connect();
$servername = "localhost";
$username = "root";
$password = "sqldba";
$dbname = "rfid_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT users.userName, nomenclature.nomenclature_Name, locations.roomNumber, makes.makeName, models.model_Name, items.rfid, items.serialNum FROM items join locations on items.location_id=locations.location_id join models on items.model_id=models.model_id join nomenclature on nomenclature.nomenclature_id=models.nom_id join makes on models.make_id=makes.make_id join users on users.user_id=items.user_id WHERE userName like '%{$selectedName}%' ";
// WHERE user.userName=$selectedName
$result = $conn->query($sql);
if (!$result) {
die("Didn't Work " . mysqli_error($conn));
}
mysqli_select_db($conn, "rfid_database");
// output data of each row
echo "<table>\r\n\t\t<tr>\r\n\t\t<th>Nomenclature</th>\r\n\t\t<th>Count</th>\r\n\t\t<th>Location</th>\r\n\t\t<th>Make</th>\r\n\t\t<th>Model</th>\r\n\t\t<th>Serial Number</th>\r\n\t\t<th>RFID</th>\t\t\r\n\t\t</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['nomenclature_Name'] . "</td>";
echo "<td> 1 </td>";
echo "<td>" . $row['roomNumber'] . "</td>";
echo "<td>" . $row['makeName'] . "</td>";
echo "<td>" . $row['model_Name'] . "</td>";
echo "<td>" . $row['serialNum'] . "</td>";
echo "<td>" . $row['rfid'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
}
示例13: init
function init()
{
$link = connect(false);
if (mysqli_select_db($link, "synapp_db")) {
mysqli_close($link);
unset($link);
return INST_DB_EXISTS;
}
$sql = "CREATE DATABASE synapp_db";
if (!mysqli_query($link, $sql)) {
die("mysql CREATE DATABASE error.");
}
$sql = "ALTER DATABASE synapp_db CHARACTER SET utf8 COLLATE utf8_unicode_ci";
if (!mysqli_query($link, $sql)) {
die("mysql ALTER DATABASE synapp_db CHARACTER SET utf8 COLLATE utf8_unicode_ci error.");
}
if (!mysqli_select_db($link, "synapp_db")) {
die("mysqli_select_db() error.");
}
create_all_languages_table($link);
$sql = "CREATE TABLE IF NOT EXISTS users (user VARCHAR(32) UNIQUE KEY,pass VARCHAR(64),recovery VARCHAR(64)," . "firstdate INT,hfirstdate BIT DEFAULT 0,missed_logins INT DEFAULT 0,last_login INT,hlast_login BIT DEFAULT 0,ip INT UNSIGNED,last_update INT," . "interface_language VARCHAR(4),hinterface_language BIT DEFAULT '0',working_group VARCHAR(32),hworking_group BIT DEFAULT 0,input_language VARCHAR(4),hinput_language BIT DEFAULT 0,hprofile BIT DEFAULT 0," . "gender VARCHAR(1) DEFAULT NULL, hgender BIT DEFAULT 0,birthday DATE, hbirthday BIT DEFAULT 0,studies VARCHAR(256), hstudies BIT DEFAULT 0,studies_type VARCHAR(64), hstudies_type BIT DEFAULT 0,studies_level INT, hstudies_level BIT DEFAULT 0, occupation VARCHAR(256),hoccupation BIT DEFAULT 0," . "email VARCHAR(128),hemail BIT DEFAULT 0,email_confirmation_code VARCHAR(64),confirmed_email BIT DEFAULT 0,avatar VARCHAR(128),hstats BIT DEFAULT 0, ditloid_lock_timestamp INT DEFAULT NULL, ditloid_time_left_when_locked INT DEFAULT 0, gotestbefore INT DEFAULT 0," . "gotestafter INT DEFAULT 0, timer_ctestb_start INT DEFAULT 0, timer_ctestb_end INT DEFAULT 0, timer_utestb_start INT DEFAULT 0, timer_utestb_end INT DEFAULT 0, timer_utesta_start INT DEFAULT 0, timer_utesta_end INT DEFAULT 0, timer_ctesta_start INT DEFAULT 0, timer_ctesta_end INT DEFAULT 0, fbid VARCHAR(255) DEFAULT NULL)";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
$sql = "CREATE TABLE `interface_languages` (native_name VARCHAR(32), iso6392_code VARCHAR(4) UNIQUE KEY, users INT DEFAULT 0)";
if (mysqli_query($link, $sql)) {
$sql = "INSERT INTO interface_languages VALUES (\"español\", \"spa\", \"0\")";
mysqli_query($link, $sql);
$sql = "INSERT INTO interface_languages VALUES (\"english\", \"eng\", \"0\")";
mysqli_query($link, $sql);
$sql = "INSERT INTO interface_languages VALUES (\"galego\", \"glg\", \"0\")";
mysqli_query($link, $sql);
$sql = "INSERT INTO interface_languages VALUES (\"polski\", \"pol\", \"0\")";
mysqli_query($link, $sql);
}
$sql = "CREATE TABLE `groups` (name VARCHAR(32), users INT DEFAULT 0)";
if (mysqli_query($link, $sql)) {
$sql = "INSERT INTO groups VALUES (\"DEFAULT_GROUP_A\", \"0\")";
mysqli_query($link, $sql);
$sql = "INSERT INTO groups VALUES (\"DEFAULT_GROUP_B\", \"0\")";
mysqli_query($link, $sql);
}
$sql = "CREATE TABLE IF NOT EXISTS `images` (id VARCHAR(69) UNIQUE KEY, name VARCHAR(32), associated_group VARCHAR(32), uploader VARCHAR(32), KEY(associated_group))";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
$sql = "CREATE TABLE IF NOT EXISTS `stats` (user VARCHAR(32),lang VARCHAR(4), day DATE,type INT," . "assigned_group VARCHAR(32), upvotes INT DEFAULT 0, downvotes INT DEFAULT 0, neutralvotes INT DEFAULT 0, popupvotes INT DEFAULT 0, popdownvotes INT DEFAULT 0, popneutralvotes INT DEFAULT 0, count INT DEFAULT 0, UNIQUE INDEX `user_lang_day_type_assigned_group` (`user`, `lang`, `day`, `type`, `assigned_group`))";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
$sql = "CREATE TABLE IF NOT EXISTS `test_ranks` (user VARCHAR(32), ttype VARCHAR(32),evals INT,orgfullvotes INT, orghalfvotes INT, orgzerovotes INT, cohfullvotes INT, cohhalfvotes INT, cohzerovotes INT, UNIQUE INDEX uti (user,ttype))";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
$sql = "CREATE TABLE IF NOT EXISTS `confirmed_emails` (user VARCHAR(32),email VARCHAR(128) UNIQUE KEY, KEY(user))";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
return INST_OK;
}
示例14: fetchLogs
function fetchLogs()
{
$url = parse_url(getenv("CLEARDB_DATABASE_URL"));
$server = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$db = substr($url["path"], 1);
$newlink = mysqli_connect($server, $username, $password);
mysqli_select_db($newlink, $db) or die("Cannot connect to database.");
$user = $_SESSION['user'];
if (isset($_POST['message'])) {
return $_POST['message'];
} else {
$newLogQry = "SELECT * FROM `players` WHERE username = '{$user}'";
if (!mysqli_query($newlink, $newLogQry)) {
echo mysqli_error($link);
} else {
$newLogRes = mysqli_query($newlink, $newLogQry);
}
$newLogRows = mysqli_fetch_array($newLogRes);
$newLog = $newLogRows['logs'];
return $newLog;
}
mysqli_close($newlink);
}
示例15: get_data
public function get_data()
{
$phoneErr = $nameErr = "";
$valid1 = $valid2 = false;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = Model_jointour::test_data($_POST['name']);
$phone = Model_jointour::test_data($_POST['phone']);
if (!preg_match("/^[a-zA-Zа-яА-Я]*\$/", str_replace(" ", "", $name))) {
$nameErr = "Wrong characters!";
} else {
$valid2 = true;
}
if (!preg_match('/^\\+?[0-9]{12,12}$/', $phone)) {
$phoneErr = "Invalid format!";
} else {
$valid1 = true;
}
}
if ($valid1 && $valid2) {
$con = mysqli_connect("localhost", "MaxMelnyk", "781227maks") or die("Something wrong...");
mysqli_select_db($con, "tour_firm") or die(mysql_error());
mysqli_query($con, 'SET NAMES utf8');
$query = "INSERT INTO tourists (tourID, name, phone) values(" . $_GET['id'] . ", '{$name}', '{$phone}')";
mysqli_query($con, $query) or die(mysql_error());
}
return $data = array('nameErr' => $nameErr, 'phoneErr' => $phoneErr);
}