本文目錄一覽:
PHP與Mysql的關係以及Mysql的常用函數介紹
mysql是種關係數據庫,php是
web開發語言,
php操作mysql最常用的函數也就那麼幾個
mysql_content
連接mysql數據
mysql_select_db
告訴mysql要操作的是哪個數據庫
mysql_query
執行的操作比如
select,insert,update,delete了,
mysql_fetch_array
讀取數據
附:
php操作mysql數據庫簡單示例
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_result()函數使用方法
mysql_result定義和用法
mysql_result()
函數返回結果集中一個字段的值。
mysql_result()
返回
MySQL
結果集中一個單元的內容。字段參數可以是字段的偏移量或者字段名,或者是字段表點字段名(tablename.fieldname)。如果給列起了別名(’select
foo
as
bar
from…’),則用別名替代列名。
如果成功,則該函數返回字段值。如果失敗,則返回
false。
調用
mysql_result()
不能和其它處理結果集的函數混合調用。
語法
mysql_result(data,row,field)
參數
描述
data
必需。規定要使用的結果標識符。該標識符是
mysql_query()
函數返回的。
row
必需。規定行號。行號從
開始。
field
可選。規定獲取哪個字段。可以是字段偏移值,字段名或
table.fieldname。
如果該參數未規定,則該函數從指定的行獲取第一個字段。
說明
當作用於很大的結果集時,應該考慮使用能夠取得整行的函數。這些函數在一次函數調用中返回了多個單元的內容,比
mysql_result()
快得多。
此外請注意,在字段參數中指定數字偏移量比指定字段名或者
tablename.fieldname
要快得多。
例子
?php
$con
=
mysql_connect(“localhost”,
“hello”,
“321”);
if
(!$con)
{
die(‘Could
not
connect:
‘
.
mysql_error());
}
$db_selected
=
mysql_select_db(“test_db”,
$con);
$sql
=
“SELECT
*
from
Person”;
$result
=
mysql_query($sql,$con);
echo
mysql_result($result,0);
mysql_close($con);
?
輸出類似:
Adams
php中mysqli替換mysql_result的官方方法
今天升級了php版本,順便想把php代碼中的mysql連接方式改成mysqli,因為官方自php5.3開始一直推薦mysqli
和
pdo
。不多說了,貼代碼
//
錯略的使用mysqli替換
if
(!function_exists(‘mysql_result’))
{
function
mysql_result($result,
$number,
$field=0)
{
mysqli_data_seek($result,
$number);
$row
=
mysqli_fetch_array($result);
return
$row[$field];
}
}
好了,這篇文章就介紹到這了。
原創文章,作者:PAXYN,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/318189.html