Kostya Cherno
Kostya Cherno

Reputation: 33

Connection to MySQL using ODBC driver in PHP code

I have a simple code for selecting data using MySQl and PHP. Here it is:

<?php
require_once 'login.php' ;

$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die ("Unable to connect to MySQL: " . mysql_error());

mysql_select_db($db_database)
or die("Unable to choose DB: " . mysql_error());

$query = "SELECT * FROM bank";
$result = mysql_query($query);
if (!$result) die ("Failed with connection to DB: " . mysql_error());
$rows = mysql_num_rows($result);
for ($j=0; $j < $rows; ++$j) { 
$row = mysql_fetch_row($result);
echo 'MFO: '   . $row[0] . '<br/>';
echo 'NAME: '  . $row[1] . '<br/>';
echo 'STATE: ' . $row[2] . '<br/><br/>';
}   
?>

But i have to use ODBC driver instead of standard integrated driver. I've read a lot of information but haven't find anything , so maybe someone help what should i add or rewrite in this code for using ODBC ?

Upvotes: 1

Views: 10283

Answers (1)

Ren&#233; H&#246;hle
Ren&#233; H&#246;hle

Reputation: 27295

There are a lot of odbc functions in PHP.

http://php.net/manual/en/function.odbc-connect.php

You can connect with this functions to mysql and other databases. In the commments on php.net you can find some examples how to connect to MySQL.

http://www.mysql.de/products/connector/

Here you can find an ODBC driver for MySQL.

Upvotes: 1

Related Questions