Connecting to ODBC databases from PHP

Below is a PHP connection string and a code sample and that show you how to connect to a database using the standard PHP functions. You should strictly adhere to standardized SQL - this will prove useful if you decide to use a different databases for your PHP app in the future, e.g. migrate from MySQL to PostgreSQL or MS SQL.

These functions also work for accessing data in cloud applications from PHP, such as Mailchimp, Salesforce, Dynamics 365, BigCommerce, or QuickBooks.

Need to connect PHP to a database? ODBC is an API that allows you to connect to a data source, such as PostgreSQL, Oracle, MySQL, MongoDB or SQL Server, using standard PHP functions and Devart ODBC Drivers. You can use PHP with databases via a connector to deliver HTML to a web browser that requests a resource.
To connect to a database and retrieve data using the PHP progamming language, you only need a few functions:
  • odbc_exec() function to execute an SQL statement;
  • odbc_fetch_row() function to return records from the result set;
  • odbc_result() function to read fields from a record;
  • finally, odbc_close() function is used to close an ODBC connection.

ODBC database connection in PHP with
odbc_connect() function

Install the driver and configure an ODBC data source in the driver settings

01.The PHP odbc_connect() function is used to connect to an ODBC data source.

$user = "myusername";
$password = "mypassword";
$ODBCConnection = odbc_connect("DRIVER={Devart ODBC Driver for SQLite};Direct=True;Database=mydatabase", $user, $password);
Start SQL Server Management Studio and create a linked server

02.The odbc_exec() function is used to execute an SQL statement.

$SQLQuery = "SELECT * FROM autotest.dept";
$RecordSet = odbc_exec($ODBCConnection, $SQLQuery);
Run a query against the data storage

03.The odbc_fetch_row() function is used to return records from the result set.

while (odbc_fetch_row($RecordSet)) {
    $result = odbc_result_all($RecordSet, "border=1");

Key Features

Direct mode

Native connection to traditional databases and cloud-based services from PHP using an ODBC driver. No need to use client software to fetch your sales figures table or a list of the best sales managers from popular data stores such as Oracle, MySQL, PostgreSQL, SQL Server, as well as cloud services such as Salesforce or Zoho CRM.

SQL data type mapping

Full support and mapping of data source-specific SQL data types to the standard ODBC data types. Access diverse data stores from PHP through a unified interface with exceptional speed. You can create custom mappings between the data source fields and ODBC data types.

Secure connection

Devart ODBC drivers use SSL / SSH and HTTPS tunneling to protect user data as it flows between a remote server on the Internet and and the machine where your PHP code is executed. Tunneling allows you to send communications securely between machines.

ANSI SQL-92 standard support for cloud services

Devart ODBC drivers address one of the major challenges of retrieving data from email marketing, CRM, accounting and other cloud applications using PHP: their lack of adequate API support for SQL-92 standard SQL commands. Our drivers are designed to get the most out of cloud service APIs.

Why pick our ODBC drivers for your PHP application?

Fully Unicode-compliant ODBC drivers

Fully Unicode-compliant ODBC drivers

Unicode is the universal standard for encoding characters in most languages. Our ODBC drivers provide a Unicode-compliant way to work with strings and characters in databases: they are capable of mapping Unicode function calls and string data types to ANSI encoding.

All major versions of data stores are supported

All major versions of data stores are supported

Our ODBC drivers can be used to interact and perform SQL CRUD operations on popular traditional databases and cloud services from PHP, such as MySQL, Oracle, PostgreSQL, Salesforce, or Mailchimp.

Regular feature update rollouts and timely bug fixes

Regular feature updates and timely bug fixes

We frequently release new versions of ODBC drivers with new capabilities or enhancements for already existing features. Changes and new features are added to the roadmap based on customer feedback. Bug fixes and minor improvements are released as nightly builds to resolve issues in a timely fashion.

Strict compliance with Microsoft ODBC 3.52 Specification

Strict compliance with Microsoft ODBC 3.52 Specification

Our ODBC drivers provide full support for the standard Open Database Connectivity API functions and data types. ODBC interface allows PHP to connect to ODBC databases using the SQL language. Additionally, we have designed Advanced Connection String parameters that implement different types of behavior.

Exceptional SQL query performance and bulk updates

Exceptional SQL query performance and bulk updates

Our ODBC drivers allow you to perform bulk record update with PHP in a single update statement while maintaining decent update speed. When you need to update a table with a million of records, you can use a single update operation which significantly reduces execution time compared to row-by-row operations.

Team of expert support engineers and community of developers

Team of expert support engineers and community of developers

Contact our friendly knowledgeable support team for assistance if have any questions about using our ODBC drivers with PHP, or join our forum to discuss anything related to the database application development with other professional developers.

Connect PHP app to your data source with our ODBC drivers

Our drivers provide Direct access to your databases and clouds from PHP, which eliminates the need to use database client libraries, simplifies the deployment process, and extends your application capabilities.

Choose Devart ODBC driver for your data source

You can try out any of these for free