php odbc in linux
yum install unixODBC
yum install php-odbc
in /etc/odbcinst.ini file
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
edit /etc/odbc.ini
mysqlmyodbc = MySQL
[mysqlmyodbc]
Driver = /usr/lib/libmyodbc5.so
Server = localhost
Port = 3306
User = username
Password = password
Database = databasename
Option = 3
Socket = /var/run/mysqld/mysqld.sock
save the /etc/odbc.ini file
service httpd restart
service mysqld restart
test php file
<?php
$conn = odbc_connect("DRIVER={MySQL};Server=localhost;Database=databasename", "username", "password");
/* $sql = "SELECT 1 as test";
$rs = odbc_exec($conn,$sql);
odbc_fetch_row($rs);
echo "\nTest\n—--\n" . odbc_result($rs,"test") . "\n";
*/
$sql = "SELECT * from table_name";
$result = odbc_exec($conn,$sql);
if($result)
{
while($row = (odbc_fetch_array($result)))
{
foreach ($row as $k=>$v)
{
echo $k."=>".$v;
echo "<br/>";
}
}
}
?>
yum install unixODBC
yum install php-odbc
in /etc/odbcinst.ini file
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
edit /etc/odbc.ini
mysqlmyodbc = MySQL
[mysqlmyodbc]
Driver = /usr/lib/libmyodbc5.so
Server = localhost
Port = 3306
User = username
Password = password
Database = databasename
Option = 3
Socket = /var/run/mysqld/mysqld.sock
save the /etc/odbc.ini file
service httpd restart
service mysqld restart
test php file
<?php
$conn = odbc_connect("DRIVER={MySQL};Server=localhost;Database=databasename", "username", "password");
/* $sql = "SELECT 1 as test";
$rs = odbc_exec($conn,$sql);
odbc_fetch_row($rs);
echo "\nTest\n—--\n" . odbc_result($rs,"test") . "\n";
*/
$sql = "SELECT * from table_name";
$result = odbc_exec($conn,$sql);
if($result)
{
while($row = (odbc_fetch_array($result)))
{
foreach ($row as $k=>$v)
{
echo $k."=>".$v;
echo "<br/>";
}
}
}
?>
No comments:
Post a Comment