本文目錄一覽:
- 1、php mysqli 常用函數有哪些
- 2、php的mysql_query()函數
- 3、PHP執行批量mysql語句的解決方法
- 4、在PHP程序中,執行Mysql命令操作的語句是??
- 5、如何用php調用mysql中的數據
php mysqli 常用函數有哪些
php 中 mysqli 是個類,這個類的函數(方法)有:
mysqli::$affected_rows — Gets the number of affected rows in a previous MySQL operation
mysqli::autocommit — 打開或關閉本次數據庫連接的自動命令提交事務模式
mysqli::begin_transaction — Starts a transaction
mysqli::change_user — Changes the user of the specified database connection
mysqli::character_set_name — 返回當前數據庫連接的默認字符編碼
mysqli::$client_info — Get MySQL client info
mysqli::$client_version — Returns the MySQL client version as a string
mysqli::close — 關閉先前打開的數據庫連接
mysqli::commit — 提交一個事務
mysqli::$connect_errno — Returns the error code from last connect call
mysqli::$connect_error — Returns a string description of the last connect error
mysqli::__construct — Open a new connection to the MySQL server
mysqli::debug — Performs debugging operations
mysqli::dump_debug_info — 將調試信息輸出到日誌
mysqli::errno — 返回最近函數調用的錯誤代碼
mysqli::$error_list — Returns a list of errors from the last command executed
mysqli::$error — Returns a string description of the last error
mysqli::$field_count — Returns the number of columns for the most recent query
mysqli::get_charset — Returns a character set object
mysqli::get_client_info — Get MySQL client info
mysqli_get_client_stats — Returns client per-process statistics
mysqli_get_client_version — 作為一個整數返回MySQL客戶端的版本
mysqli::get_connection_stats — Returns statistics about the client connection
mysqli::$host_info — 返回一個表述使用的連接類型的字符串
mysqli::$protocol_version — 返回MySQL使用的協議版本號
mysqli::$server_info — 返回MySQL服務器的版本號
mysqli::$server_version — 作為一個整數返回MySQL服務器的版本
mysqli::get_warnings — Get result of SHOW WARNINGS
mysqli::$info — Retrieves information about the most recently executed query
mysqli::init — Initializes MySQLi and returns a resource for use with mysqli_real_connect()
mysqli::$insert_id — Returns the auto generated id used in the last query
mysqli::kill — Asks the server to kill a MySQL thread
mysqli::more_results — Check if there are any more query results from a multi query
mysqli::multi_query — Performs a query on the database
mysqli::next_result — Prepare next result from multi_query
mysqli::options — Set options
mysqli::ping — Pings a server connection, or tries to reconnect if the connection has gone down
mysqli::poll — Poll connections
mysqli::prepare — Prepare an SQL statement for execution
mysqli::query — 對數據庫執行一次查詢
mysqli::real_connect — 建立一個 MySQL 服務器連接
mysqli::real_escape_string — Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection
mysqli::real_query — 執行一個mysql查詢
mysqli::reap_async_query — Get result from async query
mysqli::refresh — Refreshes
mysqli::release_savepoint — Removes the named savepoint from the set of savepoints of the current transaction
mysqli::rollback — 回退當前事務
mysqli::rpl_query_type — Returns RPL query type
mysqli::savepoint — Set a named transaction savepoint
mysqli::select_db — 選擇用於數據庫查詢的默認數據庫
mysqli::send_query — 發送請求並返回結果
mysqli::set_charset — 設置默認字符編碼
mysqli::set_local_infile_default — Unsets user defined handler for load local infile command
mysqli::set_local_infile_handler — Set callback function for LOAD DATA LOCAL INFILE command
mysqli::$sqlstate — Returns the SQLSTATE error from previous MySQL operation
mysqli::ssl_set — Used for establishing secure connections using SSL
mysqli::stat — Gets the current system status
mysqli::stmt_init — 初始化一條語句並返回一個用於mysqli_stmt_prepare(調用)的對象
mysqli::store_result — Transfers a result set from the last query
mysqli::$thread_id — Returns the thread ID for the current connection
mysqli::thread_safe — 返回是否是線程安全的
mysqli::use_result — Initiate a result set retrieval
mysqli::$warning_count — Returns the number of warnings from the last query for the given link
以上函數清單直接來自 網站。你可以進入該網站參看。
php的mysql_query()函數
你這有鑽牛角尖了。。query翻譯為中文為查詢的意思。。如果你真要扣字眼的話。。你要明白查詢和查找的區別。。詢的意思你可以百度。。是徵求意見的意思。。mysql_query的意思也就是執行mysql語句的內容的意思。。唉。。我發現我也蛋疼了。。要是你這樣一直死扣字眼是學不好東西。。雖然打破砂鍋問到底是好事。。但也要區別看是哪種問題。。
PHP執行批量mysql語句的解決方法
當有多條mysql語句連起來需要執行,比如
$sqls=
「insert
table
a
values(1,2);
insert
table
a
values(2,3);」
需要執行的話php中可以使用的方法有三個:
mysql_query
pdo
mysqli
三種方法當sqls語句沒有問題的時候都是可以的。
但是
當sql語句是錯誤的時候會出現問題
第一條sql錯誤:三個方法都返回false
第一條sql正確,第二條sql錯誤:mysql_query、pdo、
mysqli:query也是返回true。所以這個時候你是沒法判斷你的sqls是否有那條語句是錯誤的。
解決這種辦法有幾個招:
1
解析sql語句
將每條sql都拆分開來執行。這樣每個語句分開執行就解決了。但是這種方法多出了好幾種方法,所以不可取。
2
將sqls語句保存為文本
使用cmd執行命令
mysql….
.
sqls.sql,
然後捕獲輸出。這也是一種方法,但是感覺是繞着問題走,應該還有更好的方法。
3
使用mysqli::multi_query方法
這個方法可以執行多條sql語句,然後使用mysqli::next_result來設置sql的偏移量,使用mysqli::error獲取當前偏移的sql的錯誤狀態
下面是第三種方法的示例代碼
代碼如下:
複製代碼
代碼如下:
$sql
=
Config::get(‘sql’);
$content
=
file_get_contents($sql);
$config
=
Config::get(‘config’)
$mysqli
=
mysqli_connect($config[‘host’],
$config[‘user’],
$config[‘password’],
$config[‘dbname’]);
$ret
=
$mysqli-multi_query($content);
if($ret
===
false)
{
echo
mysqli_error($mysqli);
}
while
(mysqli_more_results($mysqli))
{
if
(mysqli_next_result($mysqli)
===
false)
{
echo
mysqli_error($mysqli);
echo
“\r\n”;
break;
}
}
$mysqli-close();
這樣的話當sqls語句中任意一條有錯誤的話,程序就會跳出這個錯誤。
如果你要編寫初始化mysql的腳本的話,這招就非常好用了。
在PHP程序中,執行Mysql命令操作的語句是??
第一個函數是鏈接後台數據庫服務
第二個函數是選擇數據庫
第三個函數是數據迭代器
第四個函數是執行數據庫操作語句
如何用php調用mysql中的數據
大概的基本流程如下:
連接數據庫,再加一個判斷。
選擇數據庫
讀取表
輸出表中數據
下面是代碼:
?php
$con
= mysql_connect(“localhost”,”root”,”abc123″);
/*
localhost
是服務器
root
是用戶名 abc123
是密碼*/
if
(!$con)
{
die(“數據庫服務器連接失敗”);
}
/* 這就是一個邏輯非判斷,如果錯誤就輸出括號里的字符串
*/
@mysql_select_db(“a”, $con);
/* 選擇mysql服務器里的一個數據庫,假設你的數據庫名為 a*/
$sql = “SELECT * FROM
qq”;
/*
定義變量sql, “SELECT * FROM qq”
是SQL指令,表示選取表qq中的數據 */
$result
= mysql_query($sql);
//執行SQL語句,獲得結果集
/*下面就是選擇性的輸出打印了,由於不清楚你的具體情況給你個表格打印吧*/
//打印表格
echo
“table
border=1″;
while(
$row
=
mysql_fetch_array($result)
)
/*逐行獲取結果集中的記錄,得到數組row */
{
/*數組row的下標對應着數據庫中的字段值 */
$id
=
$row[‘id’];
$name
=
$row[‘name’];
$sex
=
$row[‘sex’];
echo
“tr”;
echo
“td$id/td”;
echo
“td$name/td”;
echo
“td$sex/td”;
echo
“/tr”;
}
echo
“table
/”;
?
如果你的switch是表頭,就定義這個表頭字段,然後輸出。
你可以去後盾人平台看看,裏面的東西不錯
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/277210.html