|
|
|
1. Disclaimer
2. Introduction
3. iODBC
4. Openlink
5. PHP
6. Example
1. Disclaimer
The following document is offered in good faith as comprising only safe configuration
and procedures. No responsibility is accepted by the author for any loss or damage
caused in any way to any person or equipment, as a direct or indirect consequence of
following these instructions.
2. Introduction
In the Unix world, people may hate to be involved with any M$ related software.
However,
in the real world, the boss may require you to store data in an MS SQL database on NT
and run web application on Linux. What to do? Quit the job or sit down to read this
document? If you choose latter, I will give you a detailed installation guide so that
you can keep the job for a while. It is a How-to guide, not a Why-so guide. So don't ask
me why abc instead of cba. I don't know either. :>
PHP is becoming more and more popular in web programmers, mainly because it can be
configured
to connect to various databases like Oracle, MySQL, Solid and so on. But for a MS SQL
server, the problem is different. Though you can use PHP's Sybase-ct support features
to directly connect to MSSQL, many people(at least me) prefer to connect via ODBC.
Utilizing iODBC driver manager and Openlink ODBC middleware, you can use those
ODBC_xxxx
functions to connect to all the database Openlink has a driver for. You have to install
iODBC driver manager, Openlink Linux client and Server middleware and re-compile PHP
to support ODBC functions. In the end, I made a script sample for reference.
3. iODBC
You have to do following on this step: download Openlink-maintained version of iODBC
source code, compile and install in your Linux system, then forward to the next steps.
a. From http://www.openlinksw.com/iodbc/, download libiodbc-2-x.tar.gz. In the time
of writing, the latest version is 2.50.2.
b. gzip -dc libiodbc-2.50.2.tar.gz|tar -xof -
c. cd libiodbc-2.50.2
d. ./configure
e. make
f. make check
g. make install
These should install iODBC into your system. If you download a different version,
refers to the README and INSTALL file to look up changes.
4. Openlink
This step is a little bit complicated. You have to done works on both sides of your
Linux client machine and NT server.
4.1 On the client end:
a. From ftp://www.openlinksw.com/, download install.sh and likoxglc.taz
(for a libc6 system) or likoxxxx.taz(for a libc5 system).
b. mkdir /usr/local/openlink
c. copy install.sh and likoxglc.taz into /usr/local/openlink
d. cd /usr/local/openlink
e. sh install.sh, the install script will ask you the owner and group of the program.
It will extract things to odbcsdk directory under /usr/local/openlink and copy a
.odbc.ini into the owner's home directory.
4.2 On the server end:
a. From http://www.openlinksw.com/, download ntadm65x.zip into your NT server.
b. unzip ntadm65x.zip
c. cd disk1 directory of where you unzip the package.
d. execute setup and follow the instructions to install the Openlink middleware.
e. remember to start Openlink request broker from start menu or service control
panel.
4.3 Configuration before test
a. keep the .odbc.ini in your home directory.
b. copy the udbc.ini file from the bin directory of Openlink middleware install
directory to the /etc directory of client.
c. customize /etc/udbc.ini. In [dsn_sql6] section, change the host, database, username
and password entries to fit your server settings. Here is part of my /etc/udbc.ini:
[dsn_sql6]
Host = 10.0.0.1
ServerType = sql6
;ServerOptions =
Database = pubs
;FetchBufferSize = 30
UserName = sa
Password = xxxxxxx
d. add in your environment LD_LIBRARY_PATH='/usr/local/openlink/odbcsdk/lib' and
export
it. In csh shell, type: setenv LD_LIBRARY_PATH /usr/local/openlink/odbcsdk/lib
4.4 Test with odbctest
a. cd /usr/local/openlink/odbcsdk/examples
b. ./odbctest
c. type dsn=dsn_sql6
d. when 'sql>' appears, you can execute your sql clauses to test the connection.
5. PHP
Now we have iODBC and Openlink and can go to PHP compilation.
a. From http://www.php.net, download php-3.0.8.tar.gz
b. gzip -dc php-3.0.8.tar.gz|tar -xof -
c. cd php-3.0.8
d. ./configure --with-iodbc --with-openlink (--with-mysql --with-gd=/usr/local/gd1.3
--enable-track-vars) my configuration is to run PHP as CGI mode, support mysql, gd
as well. Your configuration may be different.
e. make --silent(don't mind if there are warning messages)
f. make install
These will install php executable into /usr/local/bin. Before you execute php, copy
the library files under /usr/local/openlink/odbcsdk/lib into /usr/lib to make it easier
for php to find openlink libraries.
If the make program reports that it can't find odbc_types.h and odbc_funcs.h, just
comment out those 2 lines in functions/php3_unified_odbc.h.
6. Example
Please refer to PHP manual for ODBC functions. Here is my example code odbc.php3:
<?
putenv("LD_LIBRARY_PATH=/usr/local/openlink/odbcsdk/lib");
putenv("UDBCINI=/etc/udbc.ini");
putenv("ODBCINI=/root/.odbc.ini");
putenv("DebugFile=/tmp/udbc.out");
$dsn="DSN=dsn_main";
$user="sa";
$password="xxxxxxx";
$sql="SELECT * FROM titles";
/* prepare and execute mode
/*
if ($conn_id=odbc_connect("$dsn","","")){
echo "connected to DSN: $dsn<br><br>";
if($result=odbc_prepare($conn_id, $sql)) {
echo "preparing to execute '$sql'<br><br>";
if (odbc_execute($result)) {
echo "executing '$sql'<BR><br>";
if($num_fields=odbc_num_fields($result)>0){
echo "$num_rows fields returned, fetching
a field<BR><br>";
odbc_fetch_field($result,&$field);
}else{
echo "not a field returned. <br><br>";
}
if($num_rows=odbc_num_rows($result)>0){
echo "$num_rows rows returned, fetching a
row<BR><br>";
odbc_fetch_row($result,&$row);
}else{
echo "not a row returned.
exiting<br><br>";
}
}else{
}
echo "freeing result<br><br>";
odbc_free_result($result);
}else{
echo "can't prepare '$sql'<br>";
}
echo "closing connection $conn_id";
odbc_close($conn_id);
}else{
echo "can not connect to DSN: $dsn<br><br>";
}
*/
/* directly execute mode */
if ($conn_id=odbc_connect("$dsn","","")){
echo "connected to DSN: $dsn<br><br>";
if($result=odbc_do($conn_id, $sql)) {
echo "executing '$sql'<br><br>";
$num_rows=odbc_num_rows($result);
if($num_rows>0){
echo "$num_rows rows returned, fetching a
row<BR><br>";
odbc_fetch_row($result,&$row);
echo "row number : $row<BR><BR>";
echo "Results:<BR>";
odbc_result_all($result);
}else{
echo "not a row returned. exiting<br><br>";
}
echo "freeing result<br><br>";
odbc_free_result($result);
}else{
echo "can not execute '$sql'<BR><BR>";
}
echo "closing connection $conn_id";
odbc_close($conn_id);
}else{
echo "can not connect to DSN: $dsn<br><br>";
}
?> |
|
| A set of functions sitting on top of the abstraction layer that makes it a little easier to do SQL stuff. Documentation is within Categories : Databases, ODBC, Complete Programs, PHP | | | Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0. Categories : Databases, PHP, mSQL, Databases | | | Recordset Class for MSSQL database Categories : PHP Classes, Databases, PHP, MS SQL Server | | | Guestbook sort by descending date and can view page by page Categories : PHP, MS SQL Server, Databases | | | Scripts to build APACHE - PHP and SQL 7.0 Categories : PHP, Databases, MS SQL Server | | | How to access MS Excel spread sheets from PHP Categories : PHP, Excel, ODBC, Databases | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | Dynamic WHERE CLAUSE depending on number of FORM FIELDS Categories : ODBC, General SQL, PHP, Complete Programs, Databases | | | Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server | | | Simple class for accessing databases like MSSql Server, Oracle etc by Raju Categories : PHP, MS SQL Server, Databases, PHP Classes, Oracle | | | how to activate connection pooling in IIS 3 and IIS 4, for access via ODBC to SQL Server 6.5
Categories : IIS, ODBC, MS SQL Server, Web Servers, Databases | | | Modification of Shane Caraveo's guestbook. Uses ODBC...some code modifications Categories : ODBC, Databases, Complete Programs, PHP | | | Mssql database Manager Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes | | | [PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more. Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL | | | This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend. Categories : Databases, PHP, ODBC, MySQL, PostgreSQL | |
|
|
|