PHP3 's MicrosoftSQL database function

Source: Internet
Author: User
Tags array empty numeric mssql php code

PHP3 's MicrosoftSQL database function

PHP3 's powerful database capabilities provide direct access to the current mainstream database in addition to the way you access the database through ODBC. Next, let's introduce the MSSQL functions in PHP3.

To invoke the MSSQL function in the PHP3 script

By default, PHP3 supports the Microsoft SQL database as an add-on module. Therefore, if you want to use the MSSQL function in your PHP code, you should first start the PHP support function for the MSSQL function. In particular, open the Php3.ini file, locate the "Extension=php3_mssql.dll" item under the "Dynamic Extensions" entry, and then cancel the ";" symbol in front of the item.

Because support for Microsoft SQL databases is an extension of PHP, users should add the following line of code at the beginning of the code that will call the MSSQL function:

DL ("Php3_mssql.dll");


Mssql_connect

Function: Establish a connection with the MS SQL Server.

Format: mssql_connect (MS SQL Server name, user name, user password);

Return value: Successfully returns the identity of the connection to the MS SQL Server.

Introduction: The Mssql_connect () function is used to establish a connection to the target MS SQL Server. The server parameter name should be a valid MS SQL Server name. A connection built with the Mssql_connect () function shuts down automatically after the PHP3 script finishes execution, or you can invoke the Mssql_close () function to shut down manually.

Mssql_pconnect

Function: Establish a permanent connection to the MS SQL Server.

Format: mssql_pconnect (MS SQL Server name, user name, user password);

Return value: Successfully returns the permanent connection identification with the MS SQL Server.

Introduction: The Mssql_pconnect () function is very similar to the Mssql_connect () function, but the main difference is that the Mssql_pconnect () function establishes a permanent connection to the MS SQL Server. The connection does not close with the end of PHP3 code execution, and the Mssql_close () function cannot force a permanent connection to be closed.

Mssql_close

Function: Closes the connection to the MS SQL Server.

Format: mssql_close (connection identification);

Return value: Returns true successfully, failure returns false.

Introduction: The Mssql_close () function closes the connection identified with the MS SQL Server for the specified connection identification. If the connection identity is not specified in the Mssql_close () function, the last established connection is closed.

Note: PHP3 does not require an explicit use of the Mssql_close () function, because a non-persistent connection automatically shuts down after the PHP3 code has finished executing.

The Mssql_close () function cannot close a permanent connection that was established using the Mssql_pconnect () function.


mssql_select_db

Function: Select MS SQL database.

Format: mssql_select_db (database name, connection identification);

Return value: Returns true successfully, failure returns false.

Introduction: The mssql_select_db () function is used to set the current active database on the server that is identified by the specified connection. If you do not specify a connection ID, the mssql_select_db () function defaults to the last established server connection.


Mssql_query

function: Transfer SQL commands to the MS SQL Server.

Format: mssql_query (query statement, connection identification);

Return value: Successfully returns the query result ID, and the failure returns false.

Introduction: The Mssql_query () function is used to transfer SQL commands to the currently active database on the server that corresponds to the specified connection identity. If you do not specify the connection identity, the Mssql_query () function automatically uses the last established connection.


Mssql_num_rows

Function: Gets the number of record bars in the query results.

Format: mssql_num_rows (query result identification);

Return value: The number of records in the query results.


Mssql_data_seek

Function: Moves the internal record pointer.

Format: Mssql_data_seek (query result identification, line);

Return value: Returns true successfully, failure returns false.

Introduction: The Mssql_data_seek () function is used to move the inner row pointer to the specified row in the query results corresponding to the specified query result identification.


Mssql_fetch_row

Function: Obtains the query result data in the form of the numerical index array.

Format: mssql_fetch_row (query result identification);

Return value: Successfully returns an array corresponding to each row of data in the query result, and the failure returns false.

Introduction: The Mssql_fetch_row () function is used to obtain the result data for the specified query result identification. Each row of data will be saved as an array, where each column of data is saved in an element of the array, with the array offset starting at 0.

Note: Each call to the Mssql_fetch_rows () function returns a new record for the next row until all rows of data are returned.


Mssql_fetch_array

Function: Gets the query result data in the form of an array.

Format: Mssql_fetch_array (query result identification);

Return value: Successfully returns an array corresponding to each row of data in the query result, and the failure returns false.

Introduction: The Mssql_fetch_array () function is an extension of the mssql_fetch_rows () function. In addition to being able to save query results in an array of numeric indices, the Mssql_fetch_array () function can also store data in the associated index, even if the field name is used as the index keyword.

Note: the Mssql_fetch_array () function does not perform faster than the Mssql_fetch_row () function, and can provide important extensions, so it is recommended that you use the Mssql_fetch_array () function instead of Mssql_ Fetch_row () function.


Mssql_fetch_object

Function: To obtain the query result data in the form of object.

Format: mssql_fetch_object (query result identification);

Return value: Successfully returns the object corresponding to the query result data, and the failure returns false.

Introduction: The Mssql_fetch_object () function is similar to the Mssql_fetch_array () function, except that the Mssql_fetch_object () function is used to get the object rather than the array. This allows the user to get the data in the object only by using the field name instead of the word segment move.

Note: the Mssql_fetch_object () function performs the same speed as the Mssql_fetch_array () function, so there is not much difference in the execution speed of the Mssql_fetch_row () function.


Mssql_num_fields

Function: Gets the number of fields in the query results.

Format: mssql_num_fields (query result identification);

Return value: Returns the number of fields in the query results.


Mssql_field_seek

Function: Set the word shift.

Format: Mssql_field_seek (query result identification, word field shift);

Function: Find the field for the specified offset.


Mssql_fetch_field

Function: Gets the field information.

Format: Mssql_fetch_field (query result identification, word field shift);

Return value: Returns the object that contains the field information.

Introduction: The Mssql_fetch_field () function can be used to get field information from the specified query results. If you do not specify a field shift, Mssql_fetch_field () automatically returns information for the next new fields.

The Mssql_fetch_field () function returns the properties of the resulting object, including:

Name: Field names.

Column_source: The database table in which the field is located.

Max_length: The maximum length of the field.

Numeric: If the field is a numeric type, the property value is 1.


Mssql_result

Function: Gets the result data of the concrete query.

Format: mssql_result (query result identification, line, field);

Return value: Returns the cell data in the query result that is located in the specified row and field.

Introduction: Mssql_result () is used to get the cell data in the query results. The field parameters can be used to move or field names. If the field name uses an alias, such as "select First_Name as name from ...", the same alias should be used in the field parameters of the Mssql_result () function.

Note: When a user's work involves a large number of query results, you should consider using a function that can get the entire row of data. Because these functions can get more than one cell information during a call, the execution speed is much faster than using the Mssql_result () function. In addition, users should be aware that when calling a function, the numeric displacement of the specified field executes much faster than the specified field name. It is recommended that users use Mssql_fetch_row (), Mssql_fetch_array (), and Mssql_fetch_object () functions more quickly in the process of using.


Mssql_free_result

Function: Empty the memory resource occupied by the query results.

Format: mssql_free_result (query result identification);

Introduction: If users are concerned that PHP3 code consumes too much memory resources during execution, you can use the Mssql_free_result () function to empty the system memory occupied by the query results identified by the specified query results. If the query result ID is not specified, all the memory resources consumed by the query results will be emptied.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.