ODBC is Open Database Connectivity it is a standard Application Programming Interface(API) and open application for accessing DBMS (Database Management System). You can access the file in an API for access the database. The main advantage of this ODBC is an application can be transmitted to other platforms when it’s coded using ODBC , both on the client side and server side, with few changes to the data access code. ODBC acts as the translation layer between the application and the Database management system. The translation will connect the application with the database using ODBC driver.

ODBC remains widely using in all the applications connectivity and the drivers are available for most platforms and most databases.

ODBC Versions

• 1.0: released in September 1992[22]
• 2.0: c. 1994
• 2.5
• 3.0: c. 1995, John Goodson of Intersolv and Frank Pellow and Paul Cotton of IBM provided significant input to ODBC 3.0[23]
• 3.5: c. 1997
• 3.8: c. 2009, with Windows 7[24]
• 4.0: Development announced June 2016[25] with draft spec on Github

To Install ODBC on cPanel server

You need to follow the command step by step to install the ODBC on cPanel server.

Step 1: First you make sure unixODBC and unixODBC -devel RPM (Redhat Package Manager). If not installed you can simply install it by the following command.

yum -y install unixODBC unixODBC-devel

Step 2: Once it is installed, run the following command to open the VIM text editor or nano.

vim /var/cpanel/easy/apache/rawopts/all_php5

Step 3: Add the following line in the file.

–with-unixODBC=/usr

Step 4: Now run the easyapache without changing anything, and it will compile ODBC into PHP.

/scripts/easyapache –build

Step 5: Once the compilation process is completed, you should have ODBC module compiled with PHP. You can check the module either using a phpinfo() file OR through shell by executing the following command.

php -i | grep odbc or php -m| grep odbc

To view the phpinfo():

Create the new file in the cPanel – File Manager under the public_html folder with the .php extension.
Example: phpinformation.php
Then open the file with the text editor and copy and paste the following command.

?php Phpinfo(); ?

Once the pasted the following code. Hit save button and close the text editor.
Go to the browser and enter the url in the address bar.

URL: http(s)://www.yourdomain.com/phpinformation.php

You can connect the ODBC remotely you need to install the drivers in your system. You can download it from the below links according to your Operating System. Then you can access the database with the database tools which is installed on your computer.

ODBC Driver for MySQL

Windows: https://www.devart.com/odbc/mysql/devartodbcmysql.exe
Linux: https://www.devart.com/odbc/mysql/devartodbcmysql-linux.tar
Mac OS X: https://www.devart.com/odbc/mysql/devartodbcmysql-osx.tar

To get the up-to-date version visit this web link: https://www.devart.com/odbc/mysql/download.html

ODBC Driver for SQLite:

Windows: https://www.devart.com/odbc/sqlite/devartodbcsqlite.exe
Linux: https://www.devart.com/odbc/sqlite/devartodbcsqlite-linux.tar
Mac OS X: https://www.devart.com/odbc/sqlite/devartodbcsqlite-osx.tar

To get the up-to-date version visit this web link: https://www.devart.com/odbc/sqlite/download.html

Some ODBC Functions:

odbc_autocommit — Toggle autocommit behaviour
odbc_binmode — Handling of binary column data
odbc_close_all — Close all ODBC connections
odbc_close — Close an ODBC connection
odbc_columnprivileges — Lists columns and associated privileges for the given table
odbc_columns — Lists the column names in specified tables
odbc_commit — Commit an ODBC transaction
odbc_connect — Connect to a datasource
odbc_cursor — Get cursor name
odbc_data_source — Returns information about a current connection
odbc_do — Alias of odbc_exec
odbc_error — Get the last error code
odbc_errormsg — Get the last error message
odbc_exec — Prepare and execute an SQL statement
odbc_execute — Execute a prepared statement
odbc_fetch_array — Fetch a result row as an associative array
odbc_fetch_into — Fetch one result row into array
odbc_fetch_object — Fetch a result row as an object
odbc_fetch_row — Fetch a row
odbc_field_len — Get the length (precision) of a field
odbc_field_name — Get the column name
odbc_field_num — Return column number
odbc_field_precision — Alias of odbc_field_len
odbc_field_scale — Get the scale of a field
odbc_field_type — Datatype of a field
odbc_foreignkeys — Retrieves a list of foreign keys
odbc_free_result — Free resources associated with a result
odbc_gettypeinfo — Retrieves information about data types supported by the data source
odbc_longreadlen — Handling of LONG columns
odbc_next_result — Checks if multiple results are available
odbc_num_fields — Number of columns in a result
odbc_num_rows — Number of rows in a result
odbc_pconnect — Open a persistent database connection
odbc_prepare — Prepares a statement for execution
odbc_primarykeys — Gets the primary keys for a table
odbc_procedurecolumns — Retrieve information about parameters to procedures
odbc_procedures — Get the list of procedures stored in a specific data source
odbc_result_all — Print result as HTML table
odbc_result — Get result data
odbc_rollback — Rollback a transaction
odbc_setoption — Adjust ODBC settings
odbc_specialcolumns — Retrieves special columns
odbc_statistics — Retrieve statistics about a table
odbc_tableprivileges — Lists tables and the privileges associated with each table
odbc_tables — Get the list of table names stored in a specific data source

Example to Use:

PHP with Pear:

PHP Scripts using the PEAR Database package to open a connection without an external DSN.
Syntax:

$dsn = "://:@:/";
$dsn -> PHP Variable.

Code:
require_once("DB.php");
$dsn = "mysql://john:pass@localhost:3306/my_db";
$db = DB::connect($dsn);

PHP with PDO

Syntax:

$dsn = "mysql:host=localhost;dbname=example";

Code:
$dbh = new PDO($dsn, $username, $password);

Categorized in:

Tagged in:

,