成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

PHP mysqli如何連接MySQL數據庫

開發 后端
PHP mysqli正確連接MySQL數據庫的首要操作就是需要開啟PHP的API支持,然后還需要將PHP mysqli預定義類,來實現我們的目的。

在學習PHP語言的時候,我們知道,在進行MySQL數據庫連接的時候我們采用了PHP mysqli這一方法。但是在實際操作中會遇到一些問題。通過本文的介紹,我們將會學到如何正確的利用PHP mysqli連接數據庫。

#t#1. 開啟PHP的API支持

(1)首先修改您的php.ini的配置文件。
      查找下面的語句:
      ;extension=php_mysqli.dll
      將其修改為:
      extension=php_mysqli.dll

(2)重新啟動Apache/IIS,即可。

(3)說明:PHP需要單獨的文件來支持這個擴展庫,一般在PHP目錄下的ext目錄里能找到php_mysqli.dll文件(PHP <= 5.0.2 中是 libmysqli.dll),當然,在PHP的配置文件當中要有正確指向ext的信息(extension_dir)。假若您的PHP沒有這個文件,您可以去下載PHP5的源碼包。另外,這個API擴展,只能在PHP5以上版本使用。其它具體信息,請看下面。

2.PHP mysqli身份證

mysqli是“MySQL, Improved”的縮寫,該擴展僅適用于PHP 5。它能用于MySQL 4.1.1和更高版本。該擴展完全支持MySQL 5.1中采用的鑒定協議,也支持預處理語句和多語句API。此外,該擴展還提供了先進的、面向對象的編程接口。

3. mysqli預定義類

mysqli

表達了 PHP 和 MySQL 數據庫之間的連接。 

構造函數

mysqli - 構造一個新的PHP mysqli對象

方法

autocommit - 打開或關閉自動提交的數據庫選項
change_user - 改變指定的數據庫連接的用戶
character_set_name - 返回數據庫連接的默認字符集
close - 關閉一個之前打開的連接
commit - 提交當前事務
connect - 打開一個到 MySQL 數據庫服務器的新連接
debug - 執行排錯操作
dump_debug_info - 取得排錯信息
get_client_info - 返回客戶端版本
get_host_info - 返回連接使用的類型
get_server_info - 返回 MySQL 服務器的版本
get_server_version - 返回 MySQL 服務器的版本
init - 初始化PHP mysqli對象
info - 取得最近執行的查詢的信息
kill - 要求服務器停止一個 mysql 線程
multi_query - 執行多個查詢
more_results - check if more results exist from currently executed multi-query
next_result - reads next result from currently executed multi-query
options - set options
ping - pings a server connection or reconnects if there is no connection
prepare - prepares a SQL query
query - performs a query
real_connect - attempts to open a connection to MySQL database server
escape_string - escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection
rollback - rolls back the current transaction
select_db - selects the default database
set_charset - sets the default client character set
ssl_set - sets ssl parameters
stat - gets the current system status
stmt_init- initializes a statement for use with mysqli_stmt_prepare
store_result - transfers a resultset from last query
thread_safe - returns whether thread safety is given or not
use_result - transfers an unbuffered resultset from last query

屬性

affected_rows - gets the number of affected rows in a previous MySQL operation
client_info - returns the MySQL client version as a string
client_version - returns the MySQL client version as an integer
errno - returns the error code for the most recent function call
error - returns the error string for the most recent function call
field_count - returns the number of columns for the most recent query
host_info - returns a string representing the type of connection used
info - retrieves information about the most recently executed query
insert_id - returns the auto generated id used in the last query
protocol_version - returns the version of the MySQL protocol used
server_info - returns a string that represents the server version number
server_version - returns the version number of the server as an integer
sqlstate - returns a string containing the SQLSTATE error code for the last error
thread_id - returns the thread ID for the current connection
warning_count - returns the number of warnings generated during execution of the previous SQL statement
 
 4. 基本語法

  1. <?php   
  2.       
  3.     /* Connect to a MySQL server  連接數據庫服務器 */   
  4.     $link = mysqli_connect(   
  5.                 'localhost',  /* The host to connect to 連接MySQL地址 */   
  6.                 'user',      /* The user to connect as 連接MySQL用戶名 */   
  7.                 'password',  /* The password to use 連接MySQL密碼 */   
  8.                 'world');    /* The default database to query 連接數據庫名稱*/   
  9.       
  10.     if (!$link) {   
  11.        printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());   
  12.        exit;   
  13.     }   
  14.       
  15.     /* Send a query to the server 向服務器發送查詢請求*/   
  16.     if ($result = mysqli_query($link, 'SELECT Name, Population FROM City ORDER BY Population DESC LIMIT 5')) {   
  17.       
  18.         print("Very large cities are: ");   
  19.       
  20.         /* Fetch the results of the query 返回查詢的結果 */   
  21.         while( $row = mysqli_fetch_assoc($result) ){   
  22.             printf("%s (%s) ", $row['Name'], $row['Population']);   
  23.         }   
  24.       
  25.         /* Destroy the result set and free the memory used for it 結束查詢釋放內存 */   
  26.         mysqli_free_result($result);   
  27.     }   
  28.       
  29.     /* Close the connection 關閉連接*/   
  30.     mysqli_close($link);   
  31.     ?> 

以上所描寫的解決辦法能夠幫助我們輕松解決PHP mysqli連接數據庫的問題。

責任編輯:曹凱 來源: 機械工業出版社
相關推薦

2010-05-27 10:10:00

連接MySQL數據庫

2010-05-14 11:12:16

連接MySql

2020-11-23 14:16:42

Golang

2021-08-02 10:53:28

PythonMySQL數據庫

2010-06-01 10:47:21

連接MySQL數據庫

2017-09-11 19:30:44

MySQLCmd命令連接數據庫

2020-09-22 15:56:31

Java

2011-05-26 13:42:50

MFC連接MySql數據庫

2018-02-26 20:00:00

編程語言JavaMySQL

2009-06-01 09:57:43

netbeans連接數netbeans數據庫netbeans連接m

2009-07-07 14:56:33

JSP連接MySQL

2009-11-30 17:54:56

PHP連接Sql數據庫

2009-12-08 17:23:12

PHP PDO類

2011-07-27 13:58:48

EclipseMySQL

2011-07-19 11:12:36

PHPMySQL數據庫

2010-05-28 10:34:39

連接MySQL數據庫

2017-11-27 11:41:06

python數據庫數據分析

2024-01-02 08:47:42

2010-06-07 15:24:34

Java連接MYSQL

2011-08-05 10:01:47

MySQL庫Pdo-MysqlMysqli
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 精品中文字幕在线 | 中文字幕在线二区 | aaaaaaa片毛片免费观看 | 亚洲欧美在线一区 | 国产精品欧美日韩 | 午夜精品一区二区三区在线观看 | 精品国产一区二区三区在线观看 | 欧美freesex黑人又粗又大 | 久久久www成人免费无遮挡大片 | 亚洲精品一级 | 日韩视频一区二区在线 | 国产999精品久久久 精品三级在线观看 | 黄色片在线观看网址 | 日本污视频 | 天天看天天干 | 亚洲精品一区二区三区中文字幕 | 午夜精品一区 | 日日夜夜天天 | 国产欧美日韩精品一区二区三区 | 高清国产一区二区 | 羞羞视频一区二区 | 欧美一区二区成人 | 日韩一区二区免费视频 | 欧美成人精品在线 | 久久精品国产久精国产 | www国产成人 | 成人毛片视频免费 | 91成人免费看片 | 亚洲一区二区综合 | 亚洲一二三在线观看 | 天天操天天干天天透 | 欧洲一区二区三区 | 久久精品中文 | 亚洲激精日韩激精欧美精品 | 精品久久久久久久久久 | 婷婷久久五月天 | 一区二区高清在线观看 | 在线观看日韩av | 日本午夜网 | 色综合国产 | www九色 |