phpmysqlin的簡單介紹

本文目錄一覽:

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存儲過程

直接上代碼:

mysql_connect(“localhost”,”user”,”pwd”);

mysql_select_db(‘testdata’) or die (mysql_error());

$sql = “create procedure tb_neaten (in rec int,in pa varchar(15),in qy decimal(10,2),in ar varchar(6))

begin

update test1 set qty=qty-qy where recordnum=rec;

insert into test2 set bname=pa,area=ar,qty=qy,date=date_format(now(),’%Y%m%d’),time=date_format(now(),’%Y%m%d’);

end;”;

mysql_query($sql) or die (mysql_error());

若是存儲過程里含有捕獲select結果的語句時,需在mysql_connect時調整參數

mysql_connect(“localhost”,”user”,”password”,1,131072) 

執行時,直接運行

 mysql_query(tb_neaten(va1,va2,va3,va4));

php怎麼用mysqli鏈接數據庫和輸出sql

一、mysql與mysqli的概念相關:

1、mysql與mysqli都是php方面的函數集,與

mysql數據庫

關聯不大。

2、在

php5

版本之前,一般是用php的

mysql函數

去驅動mysql數據庫的,比如mysql_query()的函數,屬於

面向過程

3、在php5版本以後,增加了mysqli的函數功能,某種意義上講,它是mysql系統函數的增強版,更穩定更高效更安全,與mysql_query()對應的有mysqli_query(),屬於面向對象,用對象的方式操作驅動mysql數據庫

二、mysql與mysqli的區別:

1、mysql是非持繼連接函數,mysql每次鏈接都會打開一個連接的進程。

2、mysqli是永遠連接函數,mysqli多次運行mysqli將使用同一連接進程,從而減少了服務器的開銷。mysqli封裝了諸如事務等一些高級操作,同時封裝了DB操作過程中的很多可用的方法。

三、mysql與mysqli的用法:

1:mysql(過程方式):

$conn

=

mysql_connect(‘

localhost

‘,

‘user’,

‘password’); //連接mysql數據庫

mysql_select_db

(‘data_base’);

//選擇數據庫$result

=

mysql_query(‘select

*

from

data_base’);//第二個可選參數,指定打開的連接$row

=

mysql_fetch_row(

$result

)

)

//只取一行數據echo

$row[0];

//輸出第一個字段的值

PS:mysqli以過程式的方式操作,有些函數必須指定資源,比如mysqli_query(資源標識,

SQL語句

),並且資源標識的參數是放在前面的,而mysql_query(SQL語句,’資源標識’)的資源標識是可選的,默認值是上一個打開的連接或資源。

2、mysqli(對象方式):

$conn

=

new

mysqli(‘localhost’,

‘user’,

‘password’,’data_base’);//要使用new

操作符

,最後一個參數是直接指定數據庫//假如構造時候不指定,那下一句需要$conn

select_db(‘data_base’)實現$result

=

$conn

query(

‘select

*

from

data_base’

);$row

=

$result

fetch_row();

//取一行數據echo

row[0];

//輸出第一個字段的值

使用new

mysqli(‘localhost’,

usenamer’,

‘password’,

‘databasename’);會報錯,提示如下:

Fatal

error:

Class

‘mysqli’

not

found

in

一般是mysqli是沒有開啟的,因為mysqli類不是

默認開啟

的,win下要改php.ini,去掉php_mysqli.dll前的;,linux下要把mysqli編譯進去。

四、mysql_connect()與mysqli_connect()

1.使用mysqli,可以把數據庫名稱當作參數傳給mysqli_connect()函數,也可以傳遞給mysqli的

構造函數

2.如果調用mysqli_query()或mysqli的對象查詢query()方法,則連接標識是必需的。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/254576.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-14 17:42
下一篇 2024-12-14 17:42

相關推薦

  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • Python海龜代碼簡單畫圖

    本文將介紹如何使用Python的海龜庫進行簡單畫圖,並提供相關示例代碼。 一、基礎用法 使用Python的海龜庫,我們可以控制一個小海龜在窗口中移動,並利用它的「畫筆」在窗口中繪製…

    編程 2025-04-29
  • Python櫻花樹代碼簡單

    本文將對Python櫻花樹代碼進行詳細的闡述和講解,幫助讀者更好地理解該代碼的實現方法。 一、簡介 櫻花樹是一種圖形效果,它的實現方法比較簡單。Python中可以通過turtle這…

    編程 2025-04-28
  • Python大神作品:讓編程變得更加簡單

    Python作為一種高級的解釋性編程語言,一直被廣泛地運用於各個領域,從Web開發、遊戲開發到人工智能,Python都扮演着重要的角色。Python的代碼簡潔明了,易於閱讀和維護,…

    編程 2025-04-28
  • 用Python實現簡單爬蟲程序

    在當今時代,互聯網上的信息量是爆炸式增長的,其中很多信息可以被利用。對於數據分析、數據挖掘或者其他一些需要大量數據的任務,我們可以使用爬蟲技術從各個網站獲取需要的信息。而Pytho…

    編程 2025-04-28
  • 如何製作一個簡單的換裝遊戲

    本文將從以下幾個方面,為大家介紹如何製作一個簡單的換裝遊戲: 1. 遊戲需求和界面設計 2. 使用HTML、CSS和JavaScript開發遊戲 3. 實現遊戲的基本功能:拖拽交互…

    編程 2025-04-27
  • Guava Limiter——限流器的簡單易用

    本文將從多個維度對Guava Limiter進行詳細闡述,介紹其定義、使用方法、工作原理和案例應用等方面,並給出完整的代碼示例,希望能夠幫助讀者更好地了解和使用該庫。 一、定義 G…

    編程 2025-04-27
  • 製作一個簡單的管理系統的成本及實現

    想要製作一個簡單的管理系統,需要進行技術選型、開發、測試等過程,那麼這個過程會花費多少錢呢?我們將從多個方面來闡述製作一個簡單的管理系統的成本及實現。 一、技術選型 當我們開始思考…

    編程 2025-04-27
  • 2的32次方-1:一個看似簡單卻又複雜的數字

    對於計算機領域的人來說,2的32次方-1(也就是十進制下的4294967295)這個數字並不陌生。它經常被用來表示IPv4地址或者無符號32位整數的最大值。但實際上,這個數字卻包含…

    編程 2025-04-27

發表回復

登錄後才能評論