Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 576
  • Last Modified:

ODBC on linux HowTo

I need to know how to setup odbc to work on a linux machine that already has php4.3 installed.  I know there are built in commands in php to use mysql but i would like to use odbc.  I did some research and i guess i need iodbc or unixodbc installed and odbc connector for mysql.  I also read that alot of unix odbc is already built into php so it should be easier to install unlike if it were perl.  I need a for dummies howto because i know very little linux.  I only have access to the command line.  Any help would be much appreciated :)

gmailrules  
0
gmailrules
Asked:
gmailrules
  • 3
  • 2
1 Solution
 
e-tsikCommented:
Hi :-)

If you use RedHat, then you need 3 RPMS:
php-odbc (comes with RedHat CD's)

unixODBC (also comes with RH, but I'd recommend downloading the latest version from www.unixodbc.org)

MyODBC (Connector/ODBC, Download from http://dev.mysql.com).

Configuration options are pretty straitforward. They lie in /etc/odbc.ini and /etc/odbcinst.ini

My /etc/odbcinst.ini
# From the MyODBC package
#[MySQL]
Description     = ODBC for MySQL
Driver          = /usr/lib/libmyodbc3.so
FileUsage       = 1


My /etc/odbc.ini
[asampledb]
driver = /usr/lib/libmyodbc3.so
description             = MySQL ODBC 2.50 Driver DSN
SERVER          = localhost
PORT            =
USER            = john
Password                = johnspassword
Database                = asampledb
OPTION          = 3
SOCKET          = /tmp/mysql.sock


As you can see, odbcinst.ini contains just the driver location whereas odbc.ini contains acual connection options.
Please make sure the the path to the driver is correct and there actually is a file there.

After installing, you can use the isql utility to check that your database connection is valid:
[root@server-express root]# isql asampledb
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> SELECT * FROM a_sample_table


From this point on, create a PHP page the uses the unixodbc (odbc_*) functions.

Please note, an invalid odbc_connect will cause php to segfault and you'll get a 'Page cannot be displayed' error on your browser. You have to debug this on your own without  the error message.
Note 2: Look in the mysql log for authentication errors. PHP might be restricted to use only a dedicated 'apache' user (could be also 'nobody'). You would have to create such a user and authorize it.


Enjoy!
0
 
gmailrulesAuthor Commented:
im sure that that would help if i were not such a linux newbie.  i only have access to the server through putty so im not sure if the linux cds would help.  it would be nice if you could tell me the commands on how to download the files  unzip them and intsall them.  what folders would i install them in? And them maybe i could follow your instructions from there.  Thanks a lot for the help :-)
0
 
e-tsikCommented:
I gave a 'medium-sized' explanation because I couldn't really know what your level of expertese is, and because giving too elaborate replies may be both boring and a waste of e-tsik resources :-)

First, do download the RPM'S to the server, use the command 'wget'
To download the MyODBC RPM:
wget http://ftp.gwdg.de/pub/misc/mysql/Downloads/MyODBC3/MyODBC-3.51.09-1.i586.rpm

To download unixODBC:
wget http://umn.dl.sourceforge.net/sourceforge/unixodbc/unixODBC-2.2.10-1.i386.rpm

I could not supply a link for php-odbc because you haven't specified exactly what type of linux you are using. However, you can look for that RPM in http://rpmfind.net

Some useful RPM command (filenames are for example):
To upgrade/install an existing RPM:
rpm -Uvh unixODBC-2.2.10-1.i386.rpm

To see if an RPM is installed
rpm -q php-odbc

To view the filelist of an installed RPM
rpm -q unixODBC

Note, version numbers are not included when querying RPM.
0
 
e-tsikCommented:
Correction:

To view the filelist of an installed RPM
rpm -ql unixODBC
0
 
gmailrulesAuthor Commented:
Thank you!!!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now