You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following document includes links to Azure examples showing how to connect and query Azure SQL Database and Azure SQL Managed Instance. For some related recommendations for Transport Level Security, see [TLS considerations for database connectivity](#tls-considerations-for-database-connectivity).
20
20
@@ -54,7 +54,7 @@ Get the connection information you need to connect to the database in Azure SQL
54
54
55
55
1. Review the complete **ADO.NET** connection string.
56
56
57
-
:::image type="content" source="./media/connect-query-dotnet-core/adonet-connection-string2.png" alt-text="Screenshot showing the ADO.NET connection string.":::
57
+
:::image type="content" source="media/connect-query-dotnet-core/adonet-connection-string2.png" alt-text="Screenshot showing the ADO.NET connection string.":::
58
58
59
59
1. Copy the **ADO.NET** connection string if you intend to use it.
60
60
@@ -76,20 +76,20 @@ Non-Microsoft drivers might not use TLS by default. This can be a factor when co
76
76
77
77
## Libraries
78
78
79
-
You can use various libraries and frameworks to connect to Azure SQL Database or Azure SQL Managed Instance. Check out our [Get started tutorials](https://aka.ms/sqldev) to quickly get started with programming languages such as C#, Java, Node.js, PHP, and Python. Then build an app by using SQL Server on Linux or Windows, or a SQL Server container on Linux.
79
+
You can use various libraries and frameworks to connect to Azure SQL Database or Azure SQL Managed Instance. You can then build an app by using SQL Server on Linux or Windows, or a SQL Server container on Linux.
80
80
81
81
The following table lists connectivity libraries or *drivers* that client applications can use from a variety of languages to connect to and use SQL Server running on-premises or in the cloud. You can use them on Linux, Windows, or in containers, and use them to connect to Azure SQL Database, Azure SQL Managed Instance, and Azure Synapse Analytics.
82
82
83
83
| Language | Platform | Additional resources | Download | Get started |
description: How to use PHP to create a program that connects to a database in Azure SQL Database or Azure SQL Managed Instance, and query it using T-SQL statements.
This article demonstrates how to use [PHP](https://php.net/manual/en/intro-whatis.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.
22
23
@@ -28,20 +29,16 @@ To complete this quickstart, you need:
28
29
- 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:
29
30
30
31
| Action | SQL Database | SQL Managed Instance | SQL Server on Azure VM |
| Configure |[Server-level IP firewall rule](firewall-create-server-level-portal-quickstart.md)|[Connectivity from a VM](../managed-instance/connect-vm-instance-configure.md)|
36
+
| Configure |[Server-level IP firewall rule](firewall-create-server-level-portal-quickstart.md)|[Connectivity from a VM](../managed-instance/connect-vm-instance-configure.md)|
36
37
|||[Connectivity from on-premises](../managed-instance/point-to-site-p2s-configure.md) | [Connect to a SQL Server instance](../virtual-machines/windows/sql-vm-create-portal-quickstart.md)
37
-
|Load data|Wide World Importers loaded per quickstart|[Restore Wide World Importers](../managed-instance/restore-sample-database-quickstart.md)|[Restore Wide World Importers](../managed-instance/restore-sample-database-quickstart.md)|
38
-
|||Restore or import Adventure Works from a [BACPAC](database-import.md) file from [GitHub](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works)| Restore or import Adventure Works from a [BACPAC](database-import.md) file from [GitHub](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works)|
39
-
40
-
38
+
| Load data | Wide World Importers loaded per quickstart |[Restore Wide World Importers](../managed-instance/restore-sample-database-quickstart.md)|[Restore Wide World Importers](../managed-instance/restore-sample-database-quickstart.md)|
39
+
||| Restore or import Adventure Works from a [BACPAC](database-import.md) file from [GitHub](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works)| Restore or import Adventure Works from a [BACPAC](database-import.md) file from [GitHub](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works)|
41
40
42
-
43
-
44
-
> [!IMPORTANT]
41
+
> [!IMPORTANT]
45
42
> The scripts in this article are written to use the `AdventureWorks2022` database. With a SQL Managed Instance, you must either import the `AdventureWorks2022` database into an instance database or modify the scripts in this article to use the Wide World Importers database.
46
43
47
44
- PHP-related software installed for your operating system:
@@ -50,24 +47,22 @@ To complete this quickstart, you need:
50
47
51
48
-**Linux**, install PHP, the ODBC driver, then install the PHP Driver for SQL Server. See [Step 1, 2, and 3](/sql/connect/php/installation-tutorial-linux-mac).
52
49
53
-
-**Windows**, install PHP and PHP Drivers, then install the ODBC driver and SQLCMD. See [Step 1.2 and 1.3](https://www.microsoft.com/sql-server/developer-get-started/php/windows/).
54
-
55
50
## Get server connection information
56
51
57
52
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.
58
53
59
54
1. Sign in to the [Azure portal](https://portal.azure.com/).
60
55
61
-
2. Navigate to the **SQL Databases** or **SQL Managed Instances** page.
56
+
1. Navigate to the **SQL Databases** or **SQL Managed Instances** page.
62
57
63
-
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.
58
+
1. 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.
64
59
65
-
> [!NOTE]
60
+
> [!NOTE]
66
61
> For connection information for SQL Server on Azure VM, see [Connect to a SQL Server instance](../virtual-machines/windows/sql-vm-create-portal-quickstart.md#connect-to-sql-server).
67
62
68
63
## Add code to query the database
69
64
70
-
1. In your favorite text editor, create a new file, *sqltest.php*.
65
+
1. In your favorite text editor, create a new file, *sqltest.php*.
71
66
72
67
1. Replace its contents with the following code. Then add the appropriate values for your server, database, user, and password.
description: This article shows you how to use Python to create a program that connects to a database in Azure SQL Database and query it using Transact-SQL statements.
In this quickstart, you use Python to connect to Azure SQL Database, Azure SQL Managed Instance, or Synapse SQL database and use T-SQL statements to query data.
26
26
@@ -32,19 +32,19 @@ To complete this quickstart, you need:
-[Python](https://python.org/downloads) 3 and related software
38
38
39
-
|**Action**|**macOS**|**Ubuntu**|**Windows**|
40
-
|----------|-----------|------------|---------|
41
-
|Install the ODBC driver, SQLCMD, and the Python driver for SQL Server|Use steps **1.2**, **1.3**, and **2.1** in [create Python apps using SQL Server on macOS](https://www.microsoft.com/sql-server/developer-get-started/python/mac/). These steps will also install Homebrew and Python.<br/><br/>Although the linked article references SQL Server, these steps are also applicable to Azure SQL Database, Azure SQL Managed Instance, and Azure Synapse Analytics. |[Configure an environment for pyodbc Python development](/sql/connect/python/pyodbc/step-1-configure-development-environment-for-pyodbc-python-development#linux)|[Configure an environment for pyodbc Python development](/sql/connect/python/pyodbc/step-1-configure-development-environment-for-pyodbc-python-development#windows).|
42
-
|Install Python and other required packages||Use `sudo apt-get install python python-pip gcc g++ build-essential`.||
43
-
|Further information|[Microsoft ODBC driver on macOS](/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server)|[Microsoft ODBC driver on Linux](/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server)|[Microsoft ODBC driver on Linux](/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server)|
39
+
|**Action**|**macOS**|**Linux**|**Windows**|
40
+
|---|---|---|---|
41
+
|Install the ODBC driver, **sqlcmd**, and the Python driver for SQL Server|[Configure an environment for pyodbc Python development](/sql/connect/python/pyodbc/step-1-configure-development-environment-for-pyodbc-python-development?tabs=macos)|[Configure an environment for pyodbc Python development](/sql/connect/python/pyodbc/step-1-configure-development-environment-for-pyodbc-python-development?tabs=linux)|[Configure an environment for pyodbc Python development](/sql/connect/python/pyodbc/step-1-configure-development-environment-for-pyodbc-python-development?tabs=windows).|
42
+
|Install Python and other required packages||Use `sudo apt-get install python python-pip gcc g++ build-essential`.||
43
+
|Further information|[Microsoft ODBC driver on macOS](/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server)|[Microsoft ODBC driver on Linux](/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server)|[Microsoft ODBC driver on Windows](/sql/connect/odbc/download-odbc-driver-for-sql-server)|
44
44
45
45
To further explore Python and the database in Azure SQL Database, see [Azure SQL Database libraries for Python](/python/api/overview/azure/sql), the [pyodbc repository](https://github.com/mkleehammer/pyodbc/wiki/), and a [pyodbc sample](https://github.com/mkleehammer/pyodbc/wiki/Getting-started).
46
46
47
-
## Create code to query your database
47
+
## Create code to query your database
48
48
49
49
1. In a text editor, create a new file named *sqltest.py*.
50
50
@@ -55,9 +55,9 @@ To further explore Python and the database in Azure SQL Database, see [Azure SQL
55
55
server ='<server>.database.windows.net'
56
56
database ='<database>'
57
57
username ='<username>'
58
-
password ='{<password>}'
58
+
password ='{<password>}'
59
59
driver='{ODBC Driver 17 for SQL Server}'
60
-
60
+
61
61
with pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password) as conn:
62
62
with conn.cursor() as cursor:
63
63
cursor.execute("SELECT TOP 3 name, collation_name FROM sys.databases")
0 commit comments