定義和用法
這個mysqli_refresh()函數刷新表,刷新日誌,刷新緩存。
用法
mysqli_refresh($con, options);
參數
Sr.No | 參數及說明 |
---|---|
1 |
con(Mandatory) 這是一個表示與 MySQL 服務器的連接的對象。 |
2 |
options(Mandatory) 這代表了MYSQL刷新命令的選項,可以通過逗號分隔來指定多個選項。
|
返回值
PHP mysqli_refresh() 函數返回一個布爾值,如果刷新操作成功,則為 true,否則為 false。
PHP版本
這個函數最初是在 PHP 版本 5 中引入的,適用於所有後續版本。
示例
以下示例演示了 mysqli_refresh() 函數的用法(程序風格) -
假設我們在數據庫 mydb 中創建了一個名為 my_team 的表,如下所示 -
CREATE TABLE my_team(
ID INT PRIMARY KEY AUTO_INCREMENT,
First_Name VARCHAR(255),
Last_Name VARCHAR(255),
Place_Of_Birth VARCHAR(255),
Country VARCHAR(255)
);
以下示例關閉自動提交選項並嘗試將記錄插入此表 -
<?php
//Creating a connection
$con = mysqli_connect("localhost", "root", "password", "mydb");
//Setting auto commit to true
mysqli_autocommit($con, False);
//Inserting a records into the my_team table
mysqli_query($con, "insert into my_team values(1, 'Shikhar', 'Dhawan', 'Delhi', 'India')");
mysqli_query($con, "insert into my_team values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");
mysqli_query($con, "insert into my_team values(3, 'Kumara', 'Sangakkara', 'Matale', 'Srilanka')");
mysqli_query($con, "insert into my_team values(4, 'Virat', 'Kohli', 'Delhi', 'India')");
//Closing the connection
mysqli_close($con);
?>
由於我們關閉了 auto-commit 選項,添加的記錄將不會保存在數據庫中,如果您在 MySQL 中驗證表的內容,它將為空,如下所示 $minus;
mysql> select * from my_team; Empty set (0.00 sec)
您可以使用 mysqli_query 函數將記錄刷新到表中,如下所示 $minus;
<?php
//Creating a connection
$con = mysqli_connect("localhost", "root", "password", "mydb");
//Setting auto commit to true
mysqli_autocommit($con, False);
//Inserting a records into the my_team table
mysqli_query($con, "insert into my_team values(1, 'Shikhar', 'Dhawan', 'Delhi', 'India')");
mysqli_query($con, "insert into my_team values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");
mysqli_query($con, "insert into my_team values(3, 'Kumara', 'Sangakkara', 'Matale', 'Srilanka')");
mysqli_query($con, "insert into my_team values(4, 'Virat', 'Kohli', 'Delhi', 'India')");
mysqli_refresh($con, MYSQLI_REFRESH_TABLES);
//Closing the connection
mysqli_close($con);
現在,如果您驗證表 my_team 的內容,您可以看到插入的記錄,如下所示 -
mysql> select * from my_team; +----+------------+------------+----------------+-------------+ | ID | First_Name | Last_Name | Place_Of_Birth | Country | +----+------------+------------+----------------+-------------+ | 1 | Shikhar | Dhawan | Delhi | India | | 2 | Jonathan | Trott | CapeTown | SouthAfrica | | 3 | Kumara | Sangakkara | Matale | Srilanka | | 4 | Virat | Kohli | Delhi | India | +----+------------+------------+----------------+-------------+ 4 rows in set (0.00 sec)
示例
在麵向對象的風格中,這個函數的語法是 $con->refresh();以下是麵向對象樣式 $minus 中此函數的示例;
<?php
$con = new mysqli("localhost", "root", "password", "mydb");
//Inserting a records into the players table
$con->query("CREATE TABLE IF NOT EXISTS players(First_Name VARCHAR(255), Last_Name VARCHAR(255), Country VARCHAR(255))");
//Turning the auto-commit false
$con->autocommit(FALSE);
$con->query("insert into players values('Shikhar', 'Dhawan', 'India')");
$con->query("insert into players values('Jonathan', 'Trott', 'SouthAfrica')");
//refreshing the table
$con->refresh(MYSQLI_REFRESH_TABLES);
//Closing the connection
$res = $con -> close();
?>
這將產生以下結果 -
Data Created......
如果您觀察數據庫中表的內容,您可以看到插入的記錄,如下所示 -
mysql> select * from players;
+------------+-----------+-------------+
| First_Name | Last_Name | Country |
+------------+-----------+-------------+
| Shikhar | Dhawan | India |
| Jonathan | Trott | SouthAfrica |
+------------+-----------+-------------+
2 rows in set (0.00 sec)
示例
<?php
$connection_mysql = mysqli_connect("localhost","username","password","db");
if (mysqli_connect_errno($connection_mysql)){
echo "Failed to connect to MySQL:" . mysqli_connect_error();
}
mysqli_refresh($connection_mysql,MYSQLI_REFRESH_LOG);
mysqli_close($connection_mysql);
?>
相關用法
- PHP mysqli_real_escape_string()用法及代碼示例
- PHP mysqli_real_connect()用法及代碼示例
- PHP mysqli_real_query()用法及代碼示例
- PHP mysqli_rollback()用法及代碼示例
- PHP mysqli_get_server_info()用法及代碼示例
- PHP mysqli_data_seek()用法及代碼示例
- PHP mysqli_insert_id()用法及代碼示例
- PHP mysqli_fetch_assoc()用法及代碼示例
- PHP mysqli_connect_error()用法及代碼示例
- PHP mysqli_fetch_all()用法及代碼示例
- PHP mysqli_next_result()用法及代碼示例
- PHP mysqli_stmt_affected_rows()用法及代碼示例
- PHP mysqli_begin_transaction()用法及代碼示例
- PHP mysqli_fetch_lengths()用法及代碼示例
- PHP mysqli_character_set_name()用法及代碼示例
- PHP mysqli_free_result()用法及代碼示例
- PHP mysqli_fetch_row()用法及代碼示例
- PHP mysqli_debug()用法及代碼示例
- PHP mysqli_commit()用法及代碼示例
- PHP mysqli_fetch_field()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP mysqli_refresh() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。