php的mysql函數,php操作mysql資料庫

本文目錄一覽:

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-tw/n/318189.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
PAXYN的頭像PAXYN
上一篇 2025-01-11 16:28
下一篇 2025-01-11 16:28

相關推薦

  • Python中引入上一級目錄中函數

    Python中經常需要調用其他文件夾中的模塊或函數,其中一個常見的操作是引入上一級目錄中的函數。在此,我們將從多個角度詳細解釋如何在Python中引入上一級目錄的函數。 一、加入環…

    編程 2025-04-29
  • PHP和Python哪個好找工作?

    PHP和Python都是非常流行的編程語言,它們被廣泛應用於不同領域的開發中。但是,在考慮擇業方向的時候,很多人都會有一個問題:PHP和Python哪個好找工作?這篇文章將從多個方…

    編程 2025-04-29
  • Python中capitalize函數的使用

    在Python的字元串操作中,capitalize函數常常被用到,這個函數可以使字元串中的第一個單詞首字母大寫,其餘字母小寫。在本文中,我們將從以下幾個方面對capitalize函…

    編程 2025-04-29
  • Python棧操作用法介紹

    如果你是一位Python開發工程師,那麼你必須掌握Python中的棧操作。在Python中,棧是一個容器,提供後進先出(LIFO)的原則。這篇文章將通過多個方面詳細地闡述Pytho…

    編程 2025-04-29
  • Python中set函數的作用

    Python中set函數是一個有用的數據類型,可以被用於許多編程場景中。在這篇文章中,我們將學習Python中set函數的多個方面,從而深入了解這個函數在Python中的用途。 一…

    編程 2025-04-29
  • 單片機列印函數

    單片機列印是指通過串口或並口將一些數據列印到終端設備上。在單片機應用中,列印非常重要。正確的列印數據可以讓我們知道單片機運行的狀態,方便我們進行調試;錯誤的列印數據可以幫助我們快速…

    編程 2025-04-29
  • Python 常用資料庫有哪些?

    在Python編程中,資料庫是不可或缺的一部分。隨著互聯網應用的不斷擴大,處理海量數據已成為一種趨勢。Python有許多成熟的資料庫管理系統,接下來我們將從多個方面介紹Python…

    編程 2025-04-29
  • 三角函數用英語怎麼說

    三角函數,即三角比函數,是指在一個銳角三角形中某一角的對邊、鄰邊之比。在數學中,三角函數包括正弦、餘弦、正切等,它們在數學、物理、工程和計算機等領域都得到了廣泛的應用。 一、正弦函…

    編程 2025-04-29
  • Python3定義函數參數類型

    Python是一門動態類型語言,不需要在定義變數時顯示的指定變數類型,但是Python3中提供了函數參數類型的聲明功能,在函數定義時明確定義參數類型。在函數的形參後面加上冒號(:)…

    編程 2025-04-29
  • openeuler安裝資料庫方案

    本文將介紹在openeuler操作系統中安裝資料庫的方案,並提供代碼示例。 一、安裝MariaDB 下面介紹如何在openeuler中安裝MariaDB。 1、更新軟體源 sudo…

    編程 2025-04-29

發表回復

登錄後才能評論