日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

php调mysql接口头文件_php基础系列:PHP连接MySQL数据库用到的三种API

發布時間:2024/9/19 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php调mysql接口头文件_php基础系列:PHP连接MySQL数据库用到的三种API 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參考自php手冊。本文沒有太大意義,僅為方便自己上網查閱。

1、PHP的MySQL擴展

2、PHP的mysqli擴展

3、PHP數據對象(PDO)

MySQL擴展函數

這是設計開發允許PHP應用與MySQL數據庫交互的早期擴展。mysql擴展提供了一個面向過程 的接口,并且是針對MySQL4.1.3或更早版本設計的。因此,這個擴展雖然可以與MySQL4.1.3或更新的數據庫服務端 進行交互,但并不支持后期MySQL服務端提供的一些特性。

mysql_affected_rows — 取得前一次 MySQL 操作所影響的記錄行數

mysql_client_encoding — 返回字符集的名稱

mysql_close — 關閉 MySQL 連接

mysql_connect — 打開一個到 MySQL 服務器的連接

mysql_create_db — 新建一個 MySQL 數據庫

mysql_data_seek — 移動內部結果的指針

mysql_db_name — 取得結果數據

mysql_db_query — 發送一條 MySQL 查詢

mysql_drop_db — 丟棄(刪除)一個 MySQL 數據庫

mysql_errno — 返回上一個 MySQL 操作中的錯誤信息的數字編碼

mysql_error — 返回上一個 MySQL 操作產生的文本錯誤信息

mysql_escape_string — 轉義一個字符串用于 mysql_query

mysql_fetch_array — 從結果集中取得一行作為關聯數組,或數字數組,或二者兼有

mysql_fetch_assoc — 從結果集中取得一行作為關聯數組

mysql_fetch_field — 從結果集中取得列信息并作為對象返回

mysql_fetch_lengths — 取得結果集中每個輸出的長度

mysql_fetch_object — 從結果集中取得一行作為對象

mysql_fetch_row — 從結果集中取得一行作為枚舉數組

mysql_field_flags — 從結果中取得和指定字段關聯的標志

mysql_field_len — 返回指定字段的長度

mysql_field_name — 取得結果中指定字段的字段名

mysql_field_seek — 將結果集中的指針設定為制定的字段偏移量

mysql_field_table — 取得指定字段所在的表名

mysql_field_type — 取得結果集中指定字段的類型

mysql_free_result — 釋放結果內存

mysql_get_client_info — 取得 MySQL 客戶端信息

mysql_get_host_info — 取得 MySQL 主機信息

mysql_get_proto_info — 取得 MySQL 協議信息

mysql_get_server_info — 取得 MySQL 服務器信息

mysql_info — 取得最近一條查詢的信息

mysql_insert_id — 取得上一步 INSERT 操作產生的 ID

mysql_list_dbs — 列出 MySQL 服務器中所有的數據庫

mysql_list_fields — 列出 MySQL 結果中的字段

mysql_list_processes — 列出 MySQL 進程

mysql_list_tables — 列出 MySQL 數據庫中的表

mysql_num_fields — 取得結果集中字段的數目

mysql_num_rows — 取得結果集中行的數目

mysql_pconnect — 打開一個到 MySQL 服務器的持久連接

mysql_ping — Ping 一個服務器連接,如果沒有連接則重新連接

mysql_query — 發送一條 MySQL 查詢

mysql_real_escape_string — 轉義 SQL 語句中使用的字符串中的特殊字符,并考慮到連接的當前字符集

mysql_result — 取得結果數據

mysql_select_db — 選擇 MySQL 數據庫

mysql_set_charset — Sets the client character set

mysql_stat — 取得當前系統狀態

mysql_tablename — 取得表名

mysql_thread_id — 返回當前線程的 ID

mysql_unbuffered_query — 向 MySQL 發送一條 SQL 查詢,并不獲取和緩存結果的行

PHP的mysqli擴展

mysqli擴展,我們有時稱之為MySQL增強擴展,可以用于使用 MySQL4.1.3或更新版本中新的高級特性。mysqli擴展在PHP 5及以后版本中包含。

面向對象接口

prepared語句支持

多語句執行支持

事務支持

增強的調試能力

嵌入式服務支持

如果你使用MySQL4.1.3或更新版本,強烈建議你使用這個擴展。

MySQLi {

/* 屬性 */

int $MySQLi->affected_rows;

string $client_info;

int $client_version;

string $connect_errno;

string $connect_error;

int $errno;

string $error;

int $field_count;

int $client_version;

string $host_info;

string $protocol_version;

string $server_info;

int $server_version;

string $info;

mixed $insert_id;

string $sqlstate;

int $thread_id;

int $warning_count;

/* 方法 */

int mysqli_affected_rows ( mysqli$link )

bool mysqli::autocommit ( bool$mode )

bool mysqli::change_user ( string$user ,string$password ,string$database )

string mysqli::character_set_name ( void )

string mysqli_get_client_info ( mysqli$link )

int mysqli_get_client_version ( mysqli$link )

bool mysqli::close ( void )

bool mysqli::commit ( void )

int mysqli_connect_errno ( void )

string mysqli_connect_error ( void )

mysqli mysqli_connect ([ string$host = ini_get("mysqli.default_host") [,string$username = ini_get("mysqli.default_user") [,string$passwd = ini_get("mysqli.default_pw") [,string$dbname = "" [,int $port = ini_get("mysqli.default_port") [,string$socket = ini_get("mysqli.default_socket") ]]]]]] )

bool mysqli::debug ( string$message )

bool mysqli::dump_debug_info ( void )

int mysqli_errno ( mysqli$link )

string mysqli_error ( mysqli$link )

int mysqli_field_count ( mysqli$link )

object mysqli::get_charset ( void )

string mysqli::get_client_info ( void )

array mysqli_get_client_stats ( void )

int mysqli_get_client_version ( mysqli$link )

bool mysqli::get_connection_stats ( void )

string mysqli_get_host_info ( mysqli$link )

int mysqli_get_proto_info ( mysqli$link )

string mysqli_get_server_info ( mysqli$link )

int mysqli_get_server_version ( mysqli$link )

mysqli_warningmysqli::get_warnings (void )

string mysqli_info ( mysqli$link )

mysqli mysqli::init ( void )

mixed mysqli_insert_id ( mysqli$link )

bool mysqli::kill ( int $processid )

bool mysqli::more_results ( void )

bool mysqli::multi_query ( string$query )

bool mysqli::next_result ( void )

bool mysqli::options ( int$option ,mixed$value )

bool mysqli::ping ( void )

public int mysqli::poll ( array &$read ,array&$error , array&$reject ,int $sec [,int $usec ] )

mysqli_stmt mysqli::prepare ( string$query )

mixed mysqli::query ( string$query [,int$resultmode ] )

bool mysqli::real_connect ([ string$host [,string$username [,string$passwd [,string$dbname [,int$port [,string$socket [,int$flags ]]]]]]] )

string mysqli::escape_string ( string$escapestr )

bool mysqli::real_query ( string$query )

public mysqli_result mysqli::reap_async_query (void )

bool mysqli::rollback ( void )

bool mysqli::select_db ( string$dbname )

bool mysqli::set_charset ( string$charset )

void mysqli_set_local_infile_default ( mysqli$link )

bool mysqli::set_local_infile_handler ( mysqli$link ,callback$read_func )

string mysqli_sqlstate ( mysqli$link )

bool mysqli::ssl_set ( string$key ,string$cert ,string$ca ,string$capath ,string$cipher )

string mysqli::stat ( void )

mysqli_stmt mysqli::stmt_init ( void )

mysqli_resultmysqli::store_result (void )

int mysqli_thread_id ( mysqli$link )

bool mysqli_thread_safe ( void )

mysqli_resultmysqli::use_result (void )

int mysqli_warning_count ( mysqli$link )

}

Table of Contents

mysqli->affected_rows — Gets the number of affected rows in a previous MySQL operation

mysqli::autocommit — Turns on or off auto-commiting database modifications

mysqli::change_user — Changes the user of the specified database connection

mysqli::character_set_name — Returns the default character set for the database connection

mysqli->client_info — Returns the MySQL client version as a string

mysqli->client_version — Get MySQL client info

mysqli::close — Closes a previously opened database connection

mysqli::commit — Commits the current transaction

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 — Dump debugging information into the log

mysqli->errno — Returns the error code for the most recent function call

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 — Returns the MySQL client version as a string

mysqli_get_client_stats — Returns client per-process statistics

mysqli->client_version — Get MySQL client info

mysqli::get_connection_stats — Returns statistics about the client connection

mysqli->host_info — Returns a string representing the type of connection used

mysqli->protocol_version — Returns the version of the MySQL protocol used

mysqli->server_info — Returns the version of the MySQL server

mysqli->server_version — Returns the version of the MySQL server as an integer

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 — Performs a query on the database

mysqli::real_connect — Opens a connection to a mysql server

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 — Execute an SQL query

mysqli::reap_async_query — Get result from async query

mysqli::rollback — Rolls back current transaction

mysqli::select_db — Selects the default database for database queries

mysqli::set_charset — Sets the default client character set

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 — Initializes a statement and returns an object for use with 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 — Returns whether thread safety is given or not

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數據對象(PDO)

PHP數據對象,是PHP應用中的一個數據庫抽象層規范。PDO提供了一個統一的API接口可以使得你的PHP應用不去關心具體要 連接的數據庫服務器系統類型。也就是說,如果你使用PDO的API,可以在任何需要的時候無縫切換數據庫服務器,比如從Firebird 到MySQL,僅僅需要修改很少的PHP代碼。

當然,PDO也有它自己的先進性,比如一個干凈的,簡單的,可移植的API,它最主要的缺點是會限制讓你不能使用 后期MySQL服務端提供所有的數據庫高級特性。比如,PDO不允許使用MySQL支持的多語句執行。

PDO的MySQL驅動并不是一套API,至少從PHP程序員的角度來看是這樣的。實際上,PDO的MySQL驅動處于PDO自己的下層, 提供了特定的Mysql功能。程序員直接調用PDO的API,而PDO使用了PDO的MySQL驅動完成與MySQL服務器端的交互。

PDO的MySQL驅動是眾多PDO驅動中的一個。其他可用的PDO驅動包括Firebird,PostgreSQL等等。

PDO {

__construct (string$dsn [, string$username [, string$password [,array$driver_options ]]] )

bool beginTransaction ( void )

bool commit ( void )

mixed errorCode ( void )

array errorInfo ( void )

int exec ( string $statement )

mixed getAttribute ( int $attribute )

array getAvailableDrivers ( void )

bool inTransaction ( void )

string lastInsertId ([ string$name =NULL ] )

PDOStatementprepare (string$statement [,array$driver_options = array() ] )

PDOStatementquery (string$statement )

string quote ( string $string [, int $parameter_type = PDO::PARAM_STR ] )

bool rollBack ( void )

bool setAttribute ( int $attribute , mixed$value )

}

Table of Contents

PDO::beginTransaction — Initiates a transaction

PDO::commit — Commits a transaction

PDO::__construct — Creates a PDO instance representing a connection to a database

PDO::errorCode — Fetch the SQLSTATE associated with the last operation on the database handle

PDO::errorInfo — Fetch extended error information associated with the last operation on the database handle

PDO::exec — Execute an SQL statement and return the number of affected rows

PDO::getAttribute — Retrieve a database connection attribute

PDO::getAvailableDrivers — Return an array of available PDO drivers

PDO::inTransaction — Checks if inside a transaction

PDO::lastInsertId — Returns the ID of the last inserted row or sequence value

PDO::prepare — Prepares a statement for execution and returns a statement object

PDO::query — Executes an SQL statement, returning a result set as a PDOStatement object

PDO::quote — Quotes a string for use in a query.

PDO::rollBack — Rolls back a transaction

PDO::setAttribute — Set an attribute

總結

以上是生活随笔為你收集整理的php调mysql接口头文件_php基础系列:PHP连接MySQL数据库用到的三种API的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。