MySQL数据库函数详解(目录)_MySQL
(1) int mysql_affected_rows([int link_id]);
在给定的连接中,返回由最近的DELETE、INSERT、REPLACE或者UPDATE语句所作用的行数。如果没有行 被修改,则mysql_affected_rows()返回0,如果出现错误,则返回-1。
在SELECT查询之后,mysql_affected_rows()返回所选择的行数。但一般是与SELECT语句一道使用。
(2) int mysql_close(int[link_id]);
关闭由link_id标识的与MySQL服务器的连接。如果没有指定连接,则mysql_close()关闭最近打开的连接。如果成功,则mysql_close()返回真,失败则返回假。对由mysql_pconnect()打开的永久连接,mysql_close()忽略相应的关闭请求,只是返回值。如果要关闭一个连接,就应该用mysql_connect()而不是mysql_pconnect()来打开它。
(3) int mysql_connect(string [hostname] [:port], string [username], string [password]);
本函式建立与 MySQL 伺服器的连线。其中所有的参数都可省略。当使用本函式却不加任何参数时,参数 hostname 的内定值为 localhost、参数 username 的内定值为 PHP 执行行程的拥有者、参数 password 则为空字串 (即没有密码)。而参数 hostname 后面可以加冒号与埠号,代表使用那个埠与 MySQL 连接。当然在使用资料库时,早点使用 mysql_close() 将连线关掉可以节省资源。
(4) int mysql_create_db(string db_name [, int link_id]);
告诉由link_id标识的MySQL服务器用给定的名称来创建数据库。如果数据库创建成功,则返回真;如果出现错误,则返回假。必须在数据库有创建它的CREATE权限。可能利用mysql_query()较利用mysql_create_db()发布CREATE DATABASE 语句更为适合。
(5) int mysql_data_seek(int result_id, int row_num);
由SELECT查询返回的每个结果集都有一个行游标,指示下一个提取行的函数(mysql_fetch_array()、mysql_fetch_object()或者mysql_fetch_row())调用将返回哪一行。mysql_data_seek()将给定结果集的指针设置到给定的行。行号的范围为0到mysql_num_rows()-1。如果行号合法,则mysql_data_seek()返回真,否则返回假。
[NextPage]
MySQL数据库函数详解(2)
(6) int mysql_db_query(string db_name, string query [, int link_id]);
mysql_db_query()除了提取一个额外的数据库名称参数,并在执行查询之前使它成为缺省的数据库为,与mysql_query()类似。
(7) int mysql_drop_db(string db_name, int [link_id]);
告诉由link_id标识的MySQL服务器用给定的名称来删除数据库。如果数据库删除成功,则返回真;如果出现错误,则返回假。必须有对数据库进行删除的DROP权限。
要小心这个函数;如果删除数据库,它就不存在了,且不能恢复。
使用mysql_query()较使用mysql_drop_db()发布DROP DATABASE 语句更为适合。
(8) int mysql_errno(int [link_id]);
对于给定的连接,返回含有最近返回状态的与MySQL相关的函数的错误号。零值意味着未出现错误。
(9) string mysql_error(int [link_id]);
对于给定的连接,返回含有最近返回状态的与MySQL相关的函数的错误消息字符串。空值意味着未出现错误。
(10)array mysql_fetch_array(int result, int [result_typ]);
本函数用来将查询结果 result 拆到阵列变数中。若 result 没有资料,则传回 false 值。而本函式可以说是 mysql_fetch_row() 的加强函式,除可以将传回列及数字索引放入阵列之外,还可以将文字索引放入阵列中。若是好几个传回栏位都是相同的文字名称,则最后一个置入的栏位有效,解决方法是使用数字索引或者为这些同名的栏位 (column) 取别名 (alias)。值得注意的是使用本函式的处理速度其实不会比mysql_fetch_row() 函式慢,要用哪个函式还是看使用的需求决定。参数 result_typ 是一个常数值,有以下几种常数 MYSQL_ASSOC、MYSQL_NUM 与 MYSQL_BOTH。
[NextPage]
MySQL数据库函数详解(3)
(11) object mysql_fetch_field(int result [,int col_num]);
返回结果集中给定列的相关元数据信息,如果没有这样的列,则返回假。如果省略col_num,则对mysql_fetch_field()的后继调用返回结果集后续列的信息。如果不再有剩余的列。则返回值为假。
如果指定了col_num,则其取值范围为0到mysql_num_fields()-1。在此情况下,mysql_num_fields()返回给定列的相关信息,如果col_num超出范围,返回假。
(12) array mysql_fetch_lengths(int result);
本函式将 mysql_fetch_row() 处理过的最后一列资料的各栏位资料最大长度放在阵列变数之中。若执行失败则传回 false 值。传回阵列的第一笔资料索引值是 0。
(13) object mysql_fetch_object(int result_id [, int result_typ]);
本函式用来将查询结果 result 拆到物件变数中。使用方法和 mysql_fetch_array() 几乎相同,不同的地方在于本函式传回资料是物件而不是阵列。若 result 没有资料,则传回 false 值。另外值得注意的地方是,取回的物件资料的索引只能是文字而不能用数字,这是因为物件的特性。物件资料的特性中所有的属性(property) 名称都不能是数字,因此只好乖乖使用文字字串当索引了。
参数 result_typ是一个常数值,有以下几种常数 MYSQL_ASSOC、MYSQL_NUM 与 MYSQL_BOTH。关于速度方面,本函式的处理速度几乎和mysql_fetch_row() 及 mysql_fetch_array() 二函式差不多,要用哪个函式还是看使用的需求决定。
(14) array mysql_fetch_row(int result);
作为一个数组返回给定结果集的下一行,如果没有更多的行,则返回假。
列值可作为数组元素访问,在0到mysql_num_fields()-1范围内使用列索引。
(15) string mysql_field_name(int result, int field_index);
返回结果集的给定列的名称。
col_num 的范围为0到mysql_num_fields()-1.
[NextPage]
MySQL数据库函数详解(4)
(16) int mysql_field_seek(int result, int field_offset);
为随后的mysql_fetch_field()调用设置索引。发布没有明确列号的mysql_fetch_field()的下一次调用,将返回列col_num的信息。如果搜索成功,返回真,否则返回假。
col_num的范围为0到mysql_num_fields()-1.
(17) string mysql_field_table(int result_id, int col_num);
返回结果集给定列的表名。对于计算列,此名为空。
col_num的范围为0到mysql_num_fields()-1.
(18) string mysql_field_type(int result_id, int col_num);
返回结果集给定列的类型名。类型名敬请等待参考本人的另外“MySQL列类型参考”。
col_num的范围为0到mysql_num_fields()-1.
(19) string mysql_field_flags(int result_id, int col_num);
作为字符串返回结果集中给定列的相关元数据信息,如果出现错误,则返回假。这个字符串由以空格分开的词组成,说明哪个列的标记值为真。对于假的标记,在字符串中给出相应的词。
col_num的范围为0到mysql_num_fields()-1.
(20) int mysql_field_len(int result, int field_offset);
返回结果集给定列中值可能的最大长度。
col_num的范围为0到mysql_num_fields()-1.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Analysis of the basic principles of the MySQL database management system MySQL is a commonly used relational database management system that uses structured query language (SQL) for data storage and management. This article will introduce the basic principles of the MySQL database management system, including database creation, data table design, data addition, deletion, modification, and other operations, and provide specific code examples. 1. Database Creation In MySQL, you first need to create a database instance to store data. The following code can create a file named "my

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u
