PHP connection to sql2008 (Practical)_PHP tutorial
As for the method of php connecting to mssql2008, you can refer to other articles on my blog for introduction
If you operate
We can first read the help file in the downloaded plug-in. It is very detailed but it is in English
You can also get the manual online. The convenient address for the Chinese version is
http://technet.microsoft.com/zh-cn/library/hh352126(SQL.10).aspx
http://msdn.microsoft.com/zh-cn/library/hh352126(v=SQL.10).aspx
Below is a simple test of mine
All basic functions are available
Including connecting to the database, executing SQL, getting the number and content of records, and getting the number and content of fields
$serverName = "(local)"; //Database server address
$uid = "sa"; //Database username
$pwd = "Admin777"; //Database password
$db_name="DB_FMDISP"; //Database name
$connectionInfo = array("UID"=>$uid, "PWD"=>$pwd, "Database"=>$db_name);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false)
{
echo "Connect error!";
Die( print_r( sqlsrv_errors(), true));
}
//Execute sql statement
$stmt = sqlsrv_query($conn, "SELECT TOP 1000 [uid],[uname],[upwd],[udate],[enable] FROM [DB_FMDISP].[dbo].[tb_user]", array(), array ( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
if($stmt === false )
{
echo "Error in executing query.";
Die( print_r( sqlsrv_errors(), true));
}
//Get the number of records
$row_count = sqlsrv_num_rows($stmt);
if ($row_count === false){
echo "nget row errorn".'
';
print_r(sqlsrv_errors(), true);
}
else if ($row_count >=0){
echo 'Number of rows:'."n$row_countn".'
';
}
//Get the number of columns
$field_count = sqlsrv_num_fields($stmt);
if ($field_count === false){
echo "nget row errorn".'
';
print_r(sqlsrv_errors(), true);
}
else if ($field_count >=0){
echo 'Number of columns:'."n$field_countn".'
';
}
//Get the record content of a certain column (by number)
/* Make the first row of the result set available for reading. */
if( sqlsrv_fetch( $stmt ) === false )
{
echo "Error in retrieving row.n";
Die( print_r( sqlsrv_errors(), true));
}
$name = sqlsrv_get_field( $stmt, 0);
echo 'Content:'."$name:".'
';
//show the data
//Assign the record to the array and display it (by column name)
while($row = sqlsrv_fetch_array($stmt)){
echo $row['uid']."-----".$row['uname']."-----".$row['upwd']."
";
} www.2cto.com
/* Free statement and connection resources. */
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
Commonly used SQL statements
$stmt = sqlsrv_query($conn, "INSERT INTO DB_FMDISP.dbo.tb_user(uname,upwd,udate,enable) VALUES('name','pwd','2010-10-10 10:10:00',1) ");
$stmt = sqlsrv_query($conn, "SELECT * FROM DB_FMDISP.dbo.tb_user");
API Reference (SQL Server Driver for PHP)
The API name for SQL Server Driver for PHP is sqlsrv. All sqlsrv functions begin with sqlsrv_, followed by a verb or noun. Functions followed by a verb are used to perform a specific operation, while functions followed by a noun are used to return a specific form of metadata.
SQL Server Driver for PHP contains the following functions:
Function | Description |
sqlsrv_begin_transaction | Start business. |
sqlsrv_cancel | Cancels a statement; discards any pending results of the corresponding statement. |
sqlsrv_client_info | Provides information about the client. |
sqlsrv_close | Close the connection. Releases all resources associated with the corresponding connection. |
sqlsrv_commit | Commit the transaction. |
sqlsrv_configure | Change error handling and logging configuration. |
sqlsrv_connect | Create a connection and open it. |
sqlsrv_errors | Returns error and/or warning information about the previous operation. |
sqlsrv_execute | Execute predefined statements. |
sqlsrv_fetch | Makes the next row of data available for reading. |
sqlsrv_fetch_array | Retrieve the next row of data as a numeric index array, associative array, or both. |
sqlsrv_fetch_object | Retrieve the next row of data as an object. |
sqlsrv_field_metadata | Returns field metadata. |
sqlsrv_free_stmt | Close statement. Releases all resources associated with the corresponding statement. |
sqlsrv_get_config | Returns the value of the specified configuration setting. |
sqlsrv_get_field | Retrieve a field in the current row by index. PHP return type can be specified. |
sqlsrv_has_rows | Detects whether the result set has one or more rows. |
sqlsrv_next_result | Makes the next result available for processing. |
sqlsrv_num_rows | Reports the number of rows in the result set. |
sqlsrv_num_fields | Retrieve the number of fields in the active result set. |
sqlsrv_prepare | Prepares a Transact-SQL query but does not execute the query. Implicitly bound parameters. |
sqlsrv_query | Prepare Transact-SQL queries and execute them. |
sqlsrv_rollback | Roll back the transaction. |
sqlsrv_rows_affected | Returns the number of modified rows. |
sqlsrv_send_stream_data | Sends up to eight kilobytes (8 KB) of data to the server each time the function is called. |
sqlsrv_server_info | Provides information about the server. |
Excerpted from: The power of focus

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

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
