Back to Top

PHP ODBC connection with MySQL

PHP ODBC connection with Mysql

MySQL database is usually used to store data for PHP application and data are stored using the MySQL configuration and connection.Today I am going to cover a topic which is to connect PHP and MySQL using ODBC connection as from last two-three days I was working on it.

To make ODBC connection with MySQL tables, First of all you need to install MySQL ODBC drivers that is Connector-ODBC and you can get ODBC drivers from http://www.mysql.com/downloads/connector/odbc/. Once MySQL ODBC connection driver installed in your PC, you need to configure it.

To Configure MySQL ODBC connection follow the below steps:

  1. Go to Contral Panel >> Administrative Tools and then click Data Sources (ODBC)
  2. To open the ODBC Data Source Administrator
  3. Choose the System DSN tab
  4. Click on Add in the System DSN tab
  5. Select MySQL ODBC 5.1 Driver, then click Finish
  6. Now need to configure the specific fields Data source Name for the DSN.
  7. Click OK to save the DSN

Let’s have a look

Mysql ODBC DSN

In above box, enter the name of the data source(database) you want to access and in the Server field, enter the name of the MySQL hostname that you want to access(e.g localhost) then in user and password field enter database username and password.

Also, Read MySQL Connection: Let be Assured and Database BackUp Script

Now you are connected with ODBC and you can write PHP code for odbc connection with MySQL.

The odbc_connect() function is used to connect to an ODBC data source and The odbc_exec() function is used to execute an SQL statement.

After connecting with ODBC, The odbc_fetch_row() function is used to return records from the result-set. This function returns true if it is able to return rows, otherwise false

Then, To retrieve fields The odbc_result() function is used to read fields from a record.

Let’s take one Example which show data after ODBC connection:

OUTPUT

If you have any query or confusion in above article, Do let me know.Have you developed any application using ODBC, share your thoughts in below comments section.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use Placeholder image?

Posted on 10 years ago

Bhumi

Function handling Functions in PHP

Posted on 12 years ago

Bhumi

How to use IndexedDB in HTML5

Posted on 8 years ago

Bhumi

How to detect browser in Joomla

Posted on 11 years ago

Bhumi