Home php教程 php手册 PHP3的MicrosoftSQL数据库函数

PHP3的MicrosoftSQL数据库函数

Jun 21, 2016 am 09:02 AM
array fetch mssql nbsp sql

 

PHP3MicrosoftSQL数据库函数
  
  PHP3
强大的数据库功能除了提供通过ODBC访问数据库的方式之外,还提供了对目前主流数据库的直接访问支持。下面,我们就来介绍一下PHP3中的MSSQL函数。
  
  
PHP3脚本中调用MSSQL函数
  
  
默认情况下,PHP3把对Microsoft SQL数据库的支持作为附加模块。因此,用户如果希望在自己编写的PHP代码中使用MSSQL函数的话,应当首先启动PHPMSSQL函数的支持功能。具体为,打开php3.ini文件,找到“Dynamic Extensions”条目下的“extension=php3_mssql.dll”一项,然后取消该项前面起屏蔽作用的符号即可。
  
  
由于对Microsoft SQL数据库的支持属于PHP的扩展功能,因此,用户应当在将要调用MSSQL函数的代码开头处加入如下一行代码:
  
  dl (“php3_mssql.dll”);
  
  
  mssql_connect
  
  
功能:建立与MS SQL服务器的连接。
  
  
格式:mssql_connect (MS SQL服务器名称, 用户名, 用户口令);
  
  
返回值:成功返回与MS SQL服务器的连接标识。
  
  
简介:mssql_connect()函数用来建立与目标MS SQL服务器的连接。其中的服务器参数名称应当为有效的MS SQL服务器名称。使用mssql_connect()函数建立起来的连接在PHP3脚本执行完毕之后将自动关闭,或者可以调用mssql_close()函数手动关闭。
  
  mssql_pconnect
  
  
功能:建立与MS SQL服务器的永久性连接。
  
  
格式:mssql_pconnect (MS SQL服务器名称, 用户名, 用户口令);
  
  
返回值:成功返回与MS SQL服务器的永久性连接标识。
  
  
简介:mssql_pconnect()函数与mssql_connect()函数的功能非常相似,最主要的不同在于mssql_pconnect()函数与MS SQL服务器建立的是永久性的连接,该连接不会随PHP3代码执行结束而关闭,而且使用mssql_close()函数也无法强制关闭永久性连接。
  
  mssql_close
  
  
功能:关闭与MS SQL服务器的连接。
  
  
格式:mssql_close (连接标识);
  
  
返回值:成功返回true,失败返回false
  
  
简介:mssql_close()函数用于关闭指定连接标识对应的与MS SQL服务器建立的连接。如果在mssql_close()函数中没有指明连接标识,则关闭最后建立的连接。
  
  
注意:PHP3并不要求明确使用mssql_close()函数,因为非永久性连接在PHP3代码执行完毕之后将会自动关闭。
  
  mssql_close()
函数无法关闭使用mssql_pconnect()函数建立的永久性连接。
  
  
  mssql_select_db
  
  
功能:选择MS SQL数据库。
  
  
格式:mssql_select_db (数据库名称, 连接标识);
  
  
返回值:成功返回true,失败返回false
  
  
简介:mssql_select_db()函数用于设定由指定连接标识对应的服务器上的当前活动数据库。如果不具体指名连接标识,mssql_select_db()函数将默认使用最后建立的服务器连接。
  
  
  mssql_query
  
  
功能:向MS SQL服务器传送SQL命令。
  
  
格式:mssql_query (查询语句, 连接标识);
  
  
返回值:成功返回查询结果标识,失败返回false
  
  
简介:mssql_query()函数用于向指定连接标识所对应的服务器上的当前活动数据库传送SQL命令。如果不具体指明连接标识,mssql_query()函数将自动使用最后建立的连接。
  
  
  mssql_num_rows
  
  
功能:获取查询结果中的记录条数。
  
  
格式:mssql_num_rows (查询结果标识);
  
  
返回值:查询结果中的记录数目。
  
  
  mssql_data_seek
  
  
功能:移动内部记录指针。
  
  
格式:mssql_data_seek (查询结果标识, );
  
  
返回值:成功返回true,失败返回false
  
  
简介:mssql_data_seek()函数用来移动指定查询结果标识所对应的查询结果中的内部行指针到指定行。
  
  
  mssql_fetch_row
  
  
功能:以数字索引数组的形式取得查询结果数据。
  
  
格式:mssql_fetch_row (查询结果标识);
  
  
返回值:成功返回与查询结果中的每行数据相对应的数组,失败返回false
  
  
简介:mssql_fetch_row()函数用来取得指定查询结果标识所对应的结果数据。每一行数据将会以数组的形式保存,其中每一列数据都被保存在数组的一个元素中,数组位移从0开始。
  
  
注意:每一次调用mssql_fetch_rows()函数都会返回下一行的新记录,直到返回全部数据行。
  
  
  mssql_fetch_array
  
  
功能:以数组形式取得查询结果数据。
  
  
格式:mssql_fetch_array (查询结果标识);
  
  
返回值:成功返回与查询结果中的每行数据相对应的数组,失败返回false
  
  
简介:mssql_fetch_array()函数是对mssql_fetch_rows()函数的扩展。除了能够把查询结果保存在数字索引的数组中外,mssql_fetch_array()函数还可以把数据保存在关联索引中,即使用字段名作为索引关键字。
  
  
注意:mssql_fetch_array()函数的执行速度并不低于mssql_fetch_row()函数,而且可以提供很重要的扩展功能,因此建议用户可以使用mssql_fetch_array()函数来代替mssql_fetch_row()函数。
  
  
  mssql_fetch_object
  
  
功能:以对象形式取得查询结果数据。
  
  
格式:mssql_fetch_object (查询结果标识);
  
  
返回值:成功返回属性与查询结果数据相对应的对象,失败返回false
  
  
简介:mssql_fetch_object()函数的作用与mssql_fetch_array()函数类似,唯一不同在于使用mssql_fetch_object()函数得到的将是对象而非数组。这样,用户就只能使用字段名而非字段位移来获得对象中的数据。
  
  
注意:mssql_fetch_object()函数的执行速度与mssql_fetch_array()函数相同,因此与mssql_fetch_row()函数的执行速度没有太大区别。
  
  
  mssql_num_fields
  
  
功能:获取查询结果中的字段数。
  
  
格式:mssql_num_fields (查询结果标识);
  
  
返回值:返回查询结果中的字段数。
  
  
  mssql_field_seek
  
  
功能:设定字段位移。
  
  
格式:mssql_field_seek (查询结果标识, 字段位移);
  
  
功能:查找指定位移的字段。
  
  
  mssql_fetch_field
  
  
功能:获取字段信息。
  
  
格式:mssql_fetch_field (查询结果标识, 字段位移);
  
  
返回值:返回包含字段信息的对象。
  
  
简介:mssql_fetch_field()函数可以被用来获取指定查询结果中的字段信息。如果不具体指明字段位移,mssql_fetch_field()将自动返回下一个新的字段的信息。
  
  mssql_fetch_field()
函数返回结果对象的属性包括:
  
  name
:字段名称。
  
  column_source
:字段所在的数据库表格。
  
  max_length
:字段的最大长度。
  
  Numeric
:如果字段为数字类型则该属性值为1
  
  
  mssql_result
  
  
功能:获取具体查询结果数据。
  
  
格式:mssql_result (查询结果标识, , 字段);
  
  
返回值:返回查询结果中位于指定行和字段的单元格数据。
  
  
简介:mssql_result()用来获取查询结果中的单元格数据。其中的字段参数可以使用字段位移或字段名。如果字段名称使用了别名,例如:“select first_name as name from...”,则应当在mssql_result()函数的字段参数中也使用同样的别名。
  
  
注意:当用户的工作涉及到大量的查询结果时,应当考虑使用可以取得整行数据的函数。因为这些函数可以在一次调用的过程中获取多个单元格信息,所以执行速度要比使用mssql_result()函数快许多。另外,用户应当注意在调用函数时,指定字段的数字位移的执行速度要远远快于指定字段名称的执行速度。建议用户在使用过程中多采用执行速度更快的mssql_fetch_row()mssql_fetch_array(),以及mssql_fetch_object()函数。
  
  
  mssql_free_result
  
  
功能:清空查询结果所占用的内存资源。
  
  
格式:mssql_free_result (查询结果标识);
  
  
简介:如果用户担心PHP3代码在执行过程中占用过多内存资源的话,可以使用mssql_free_result()函数来清空指定查询结果标识所对应的查询结果所占用的系统内存。如果没有具体指明查询结果标识,所有查询结果占用的内存资源都将被全部清空。
  
  



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

What is the difference between HQL and SQL in Hibernate framework? What is the difference between HQL and SQL in Hibernate framework? Apr 17, 2024 pm 02:57 PM

HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

Usage of division operation in Oracle SQL Usage of division operation in Oracle SQL Mar 10, 2024 pm 03:06 PM

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Comparison and differences of SQL syntax between Oracle and DB2 Comparison and differences of SQL syntax between Oracle and DB2 Mar 11, 2024 pm 12:09 PM

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Feb 26, 2024 pm 07:48 PM

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati

See all articles