定義和用法
這個mysqli_real_query()函數接受一個表示查詢的字符串值作為參數之一,並在數據庫上執行/執行給定的查詢。查詢中傳遞的數據應該正確轉義。
用法
mysqli_real_query($con, $query)
參數
Sr.No | 參數及說明 |
---|---|
1 |
con(Mandatory) 這是一個表示與 MySQL 服務器的連接的對象。 |
2 |
query(Mandatory) 這是一個字符串值,表示要執行的查詢。傳遞給此查詢的數據應正確轉義。 |
返回值
此查詢返回一個布爾值,成功時為真,失敗時為假。
PHP版本
這個函數最初是在 PHP 版本 5 中引入的,適用於所有後續版本。
示例
以下示例演示了 mysqli_real_query() 函數的用法(程序風格) -
<?php
$con = mysqli_connect("localhost", "root", "password", "mydb");
mysqli_query($con, "CREATE TABLE IF NOT EXISTS my_team(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))");
print("Table Created ..."."\n");
//Inserting a records into the my_team table
mysqli_real_query($con, "insert into my_team values(1, 'Shikhar', 'Dhawan', 'Delhi', 'India')");
mysqli_real_query($con, "insert into my_team values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");
mysqli_real_query($con, "insert into my_team values(3, 'Kumara', 'Sangakkara', 'Matale', 'Srilanka')");
mysqli_real_query($con, "insert into my_team values(4, 'Virat', 'Kohli', 'Delhi', 'India')");
print("Records Inserted ..."."\n");
//Closing the connection
mysqli_close($con);
?>
這將產生以下結果 -
Table Created ... Records Inserted ..
示例
在麵向對象的風格中,這個函數的語法是 $con->real_query();以下是麵向對象樣式 $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))");
$con->real_query("insert into players values('Shikhar', 'Dhawan', 'India')");
$con->real_query("insert into players values('Jonathan', 'Trott', 'SouthAfrica')");
print("Data Created......");
//Closing the connection
$res = $con -> close();
?>
這將產生以下結果 -
Data Created......
相關用法
- PHP mysqli_real_escape_string()用法及代碼示例
- PHP mysqli_real_connect()用法及代碼示例
- PHP mysqli_refresh()用法及代碼示例
- 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_real_query() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。