Hướng dẫn microsoft php

Chuyển đến nội dung chính

Trình duyệt này không còn được hỗ trợ nữa.

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Tải xuống Microsoft Edge Xem thêm thông tin về Internet Explorer và Microsoft Edge

Đọc bằng tiếng Anh

Đọc bằng tiếng Anh Phản hồi Chỉnh sửa

Getting Started with the Microsoft Drivers for PHP for SQL Server

  • Bài viết
  • 09/09/2022
  • 2 phút để đọc

Trong bài viết này

Hướng dẫn microsoft php
Download PHP driver

This section provides information about the system requirements for using the Microsoft Drivers for PHP for SQL Server, and for loading the driver into the PHP process space.

Getting Started

  • Step 1: Configure development environment for PHP development
  • Step 2: Create a database for PHP development
  • Step 3: Proof of concept connecting to SQL using PHP
  • Step 4: Connect resiliently to SQL with PHP

See Also

Example Application (SQLSRV Driver)

Programming Guide for the Microsoft Drivers for PHP for SQL Server

SQLSRV Driver API Reference

Phản hồi

Gửi và xem ý kiến phản hồi dành cho

Sản phẩm này Trang này

Xem tất cả ý kiến phản hồi về trang

Trong bài viết này

Chuyển đến nội dung chính

Trình duyệt này không còn được hỗ trợ nữa.

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Tải xuống Microsoft Edge Xem thêm thông tin về Internet Explorer và Microsoft Edge

Đọc bằng tiếng Anh

Đọc bằng tiếng Anh Phản hồi Chỉnh sửa

Step 1: Configure environment for PHP development

  • Bài viết
  • 09/14/2022
  • 2 phút để đọc

Trong bài viết này

Download PHP driver

  • Identify which version of the PHP driver you will use, based on your environment, as noted here: System Requirements for the Microsoft Drivers for PHP for SQL Server
  • Download and install applicable PHP Driver here: Download Microsoft PHP Driver
  • Download and install applicable ODBC Driver here: Download ODBC Driver for SQL Server
  • Configure the PHP driver and web server for your specific operating system:

Windows

  • Configure loading the PHP driver, as noted here: Loading the Microsoft Drivers for PHP for SQL Server
  • Configure IIS to host PHP applications, as noted here: Configuring IIS for the Microsoft Drivers for PHP for SQL Server

Linux and macOS

  • Configure loading the PHP driver and configure your web server to host PHP applications, as noted here: PHP Linux and macOS Drivers Installation Tutorial

Phản hồi

Gửi và xem ý kiến phản hồi dành cho

Sản phẩm này Trang này

Xem tất cả ý kiến phản hồi về trang

Trong bài viết này

Chuyển đến nội dung chính

Trình duyệt này không còn được hỗ trợ nữa.

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Quickstart: Use PHP to query a database in Azure SQL Database

  • Bài viết
  • 08/31/2022
  • 2 phút để đọc

Trong bài viết này

Applies to: Azure SQL Database Azure SQL Managed Instance

This article demonstrates how to use PHP to connect to a database in Azure SQL Database or Azure SQL Managed Instance. You can then use T-SQL statements to query data.

Prerequisites

To complete this quickstart, you need:

  • An Azure account with an active subscription. Create an account for free.

  • A database in Azure SQL Database or Azure SQL Managed Instance. You can use one of these quickstarts to create and then configure a database:

    ActionSQL DatabaseSQL Managed InstanceSQL Server on Azure VM
    Create Portal Portal Portal
    CLI CLI
    PowerShell PowerShell PowerShell
    Configure Server-level IP firewall rule Connectivity from a VM
    Connectivity from on-premises Connect to a SQL Server instance
    Load data Adventure Works loaded per quickstart Restore Wide World Importers Restore Wide World Importers
    Restore or import Adventure Works from a BACPAC file from GitHub Restore or import Adventure Works from a BACPAC file from GitHub

    Important

    The scripts in this article are written to use the Adventure Works database. With a SQL Managed Instance, you must either import the Adventure Works database into an instance database or modify the scripts in this article to use the Wide World Importers database.

  • PHP-related software installed for your operating system:

    • macOS, install PHP, the ODBC driver, then install the PHP Driver for SQL Server. See Step 1, 2, and 3.

    • Linux, install PHP, the ODBC driver, then install the PHP Driver for SQL Server. See Step 1, 2, and 3.

    • Windows, install PHP and PHP Drivers, then install the ODBC driver and SQLCMD. See Step 1.2 and 1.3.

Get server connection information

Get the connection information you need to connect to the database in Azure SQL Database. You'll need the fully qualified server name or host name, database name, and login information for the upcoming procedures.

  1. Sign in to the Azure portal.

  2. Navigate to the SQL Databases or SQL Managed Instances page.

  3. On the Overview page, review the fully qualified server name next to Server name for a database in Azure SQL Database or the fully qualified server name (or IP address) next to Host for an Azure SQL Managed Instance or SQL Server in an Azure VM. To copy the server name or host name, hover over it and select the Copy icon.

Add code to query the database

  1. In your favorite text editor, create a new file, sqltest.php.

  2. Replace its contents with the following code. Then add the appropriate values for your server, database, user, and password.

     "your_database", // update me
            "Uid" => "your_username", // update me
            "PWD" => "your_password" // update me
        );
        //Establishes the connection
        $conn = sqlsrv_connect($serverName, $connectionOptions);
        $tsql= "SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName
             FROM [SalesLT].[ProductCategory] pc
             JOIN [SalesLT].[Product] p
             ON pc.productcategoryid = p.productcategoryid";
        $getResults= sqlsrv_query($conn, $tsql);
        echo ("Reading data from table" . PHP_EOL);
        if ($getResults == FALSE)
            echo (sqlsrv_errors());
        while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
         echo ($row['CategoryName'] . " " . $row['ProductName'] . PHP_EOL);
        }
        sqlsrv_free_stmt($getResults);
    ?>
    

Run the code

  1. At the command prompt, run the app.

    php sqltest.php
    
  2. Verify the top 20 rows are returned and close the app window.

Next steps

  • Design your first database in Azure SQL Database
  • Microsoft PHP Drivers for SQL Server
  • Report issues or ask questions
  • Retry logic example: Connect resiliently to Azure SQL with PHP

Phản hồi

Gửi và xem ý kiến phản hồi dành cho