"IODBCPHPHOWTO" . . . . . . "IODBCPHPHOWTO" . . . . "---+ iODBC-PHP-Apache HOWTO for Linux/UNIX Systems\r\n\r\n\r\n%TOC%\r\n\r\n---++Disclaimer \r\n\r\nThe following is a HOWTO document for installing PHP with iODBC as an\r\nApache module on Linux or Unix. Feel free to criticize, suggest\r\nmodifications, or ask further questions. It is currently maintained by Tim\r\nHaynes of Openlink Software (iodbc@openlinksw.com).\r\n\r\nPrerequisites include basic Unix familiarity, such as creating directories\r\nand users, using an editor, etc.\r\n\r\nThis HOWTO is intended to assist in connecting php/apache to back end\r\ndatabases via ODBC in a development environment and should not take the\r\nplace of thorough testing before deployment on a production system.\r\n\r\n\r\n---++ ODBC Overview\r\n\r\nODBC (Open Database Connectivity) is an operating system- and\r\ndatabase-independent communication API that allows a client application\r\n(productivity tool, other database, web page, custom application, etc.) to\r\ncommunicate via standards-based function calls to a backend database\r\nwithout relying on that vendor's proprietary communication protocols.\r\n\r\nODBC connections involve an application, driver manager, driver, and\r\ndatabase. The driver manager under Microsoft Windows platforms is the ODBC\r\nControl Panel. The driver manager registers a set of ODBC driver connection\r\nparameters called a Data Source Name (DSN). An application looks to the\r\ndriver manager for a DSN, and then passes the connection parameters\r\nspecified in the DSN to the appropriate driver, which makes the connection.\r\nUnder non-Windows platforms you may need to install a Driver Manager.\r\n\r\n iODBC is an Open Source Driver Manager maintained by OpenLink Software. It\r\nis released under a dual LGPL / BSD license.\r\n\r\n\r\n---++ Preface\r\n\r\nYou will also need an ODBC Driver and Database to complete the architecture.\r\n\r\nIf you need ODBC drivers to connect to a third-party database on the same\r\nor another machine, [[http://uda.openlinksw.com/odbc/][OpenLink ODBC Drivers]] are available, and may be\r\n[[https://shop.openlinksw.com/license_generator/uda/][downloaded for free trial]].\r\n\r\nThe [[http://virtuoso.openlinksw.com/][Virtuoso database]] may also be \r\n[[https://shop.openlinksw.com/license_generator/virtuoso/][downloaded for free trial]].\r\n\r\nSupport with downloading, installing, configuring, and testing these OpenLink products may be obtained \r\nthrough the\r\n[[http://community.openlinksw.com/][OpenLink Community Space]].\r\n\r\n---++ Compiling PHP with linked iODBC Driver Manager as an Apache shared module\r\n\r\nThe process is fairly straightforward. You will need to be a user who has\r\nsufficient privileges to perform all of these steps as well. Root\r\nprivileges can be obtained by typing su root and entering your root\r\npassword, but be forewarned that you can easily destroy your system as\r\nroot. If you use root privileges, please do so on a test machine.\r\n\r\nSet up a build location, and get the latest builds of\r\n[[http://www.iodbc.org/][iODBC]], [[http://httpd.apache.org/][Apache]],\r\nand [[http://www.php.net/][PHP]].\r\n\r\nSet some environment variables:\r\n\r\n\r\nexport LD_LIBRARY_PATH=/usr/local/src/odbcsdk/lib:$LD_LIBRARY_PATH\r\n\r\n - this tells the compiler where to find the driver manager.\r\n\r\nIf you prefer to statically link iODBC then remove or rename libiodbc.so\r\nfrom the above path, and libiodbc.a will be statically linked instead.\r\n\r\n---++ Building Apache\r\n\r\nWe build apache with support for dynamic modules and APXS:\r\n\r\n\r\n\r\ncd httpd-1.3.*\r\n./configure --prefix=/usr/local/apache --enable-module=so --enable-mods-shared=[list of modules]\r\nnice make && su root -c 'make install'\r\n\r\n\r\nChoose the list of modules to go with whatever you expect to be loading\r\nfrom your httpd.conf (or similar). Among other things, authentication,\r\ndav (in the case of Apache 2.x), ssl, virtualhosting, user-tracking,\r\nspelling-correction, proxying, SSI, fine control of MIME data, etc. -- these\r\nare all configurable at this time.\r\n\r\nAfter a while, Apache should finish compiling and install itself into\r\n/usr/local/apache/.\r\n\r\n\r\n---++ Compiling PHP\r\n\r\nUnpack the PHP sources with a command like --\r\n\r\n\r\ntar xvpfj php-4.3.2.tar.bz2\r\n\r\n\r\n-- and change into the resultant directory.\r\n\r\nNote: if you are using iodbc-3.51.0, this will expose a problem in PHP's\r\nconfigure script whereby it assumes the only library required is -liodbc,\r\nwhen it should be calling \"iodbc-config --libs\" to determine the LDFLAGS\r\nrequired. This causes a debug.log to be created as PHP is configured, and\r\nwhile it may build seemingly to completion, the resultant PHP library will\r\ngive unresolved symbol errors, and apache will fail to start.\r\n[[%ATTACHURLPATH%/php-configure-iodbc.diff][This patch]] can be applied to PHP's\r\n./configure script to avoid the problem.\r\n\r\nPHP needs to be configured with a pointer both to Apache that you installed\r\nearlier, and to the ODBC SDK (iodbc directory):\r\n\r\n\r\n\r\nbash$ ./configure --prefix=$HOME/php5 \\\r\n--enable-discard-path \\\r\n--with-layout=GNU \\\r\n--with-openlink=/usr/local/openlink/odbcsdk \\\r\n--enable-experimental-zts \\\r\n--with-regex=php \\\r\n--enable-experimental-zts \\\r\n--enable-debug \\\r\n--enable-calendar \\\r\n--with-iodbc=/usr/local/openlink/odbcsdk \\\r\n--without-mysql \\\r\n--disable-sockets \\\r\n--disable-cli \\\r\n--with-apxs=/usr/local/apache/sbin/apxs \\\r\n--enable-embed=share{,d}\r\n\r\nbash$ nice make\r\nbash$ su root -c 'make install'\r\n\r\n\r\nThe process of installing here will invoke apxs, Apache's utility for\r\nmaking installation of modules an awful lot easier. This should also\r\ninclude making minor changes to your httpd.conf (so to be safe, back it up\r\nfirst) - namely these:\r\n\r\n\r\nLoadModule php5_module extramodules/libphp5.so\r\n\r\n\r\nand\r\n\r\n\r\nAddModule mod_php5.c\r\n\r\n\r\nAlso, the following should be set:\r\n\r\n\r\nAddType application/x-httpd-php .php .php4 .php3 .phtml \r\nAddType application/x-httpd-php-source .phps\r\n\r\n\r\n---++ Restarting Apache\r\n\r\nUse the command:\r\n\r\n\r\n/usr/local/apache/sbin/apachectl start\r\n\r\nto start apache.\r\n\r\nShould it fail to start, you'll be best off checking logs/error_log to see\r\nwhy it failed: there are a multitude of possible configuration errors, from\r\ntypos, through failure to access files to which it should have permission,\r\nprocesses already using the socket configured for listening, and more.\r\n\r\n\r\n---++ Checking your PHP installation\r\n\r\nCreate a simple PHP starter script, e.g., info.php, containing nothing but the line:\r\n\r\n\r\n<?php phpinfo(); ?>\r\n\r\n\r\nEnsure that the permissions are acceptable - 644 (owner read+write, everyone else \r\nread-only) should suffice.\r\n\r\nPut it in your htdocs/ directory, or somewhere else accessible under your webserver \r\nconfiguration (e.g., ~/public_html/).\r\n\r\nPoint your browser to http://localhost/info.php to see all PHP's\r\nconfiguration information.\r\n\r\n---++ Environment Variable concerns\r\n\r\nThere are two files that your ODBC-using PHP scripts must be able to access:\r\n\r\n* libiodbc.so - PHP requires this to be in the list of directories\r\n searched, so if you export LD_LIBRARY_PATH either before starting apache,\r\n or using the SetEnv directive in httpd.conf, it should be able to access\r\n the driver manager.\r\n\r\n* odbc.ini - this is accessed by the driver manager, libiodbc.so, and\r\n contains a list of all your DSNs and their connect info, etc. In order to\r\n find this, iODBC uses the ODBCINI environment variable, or failing that\r\n it will search /etc/odbc.ini or ~/.odbc.ini instead. You can either\r\n export this in httpd.conf, or before Apache starts, or from within your\r\n PHP script itself with the setenv() function call. \r\n\r\n\r\n---++ Sample PHP script\r\n\r\nThe following script effects a connection to a database (Local Virtuoso Demo is the default DSN), \r\nand either executes a query or lists tables present in that database.\r\n\r\n\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> \r\n\r\n<html>\r\n<head>\r\n<title>OpenLink Virtuoso test of ODBC access through PHP hosting</title>\r\n<link type=\"text/css\" rel=\"STYLESHEET\" \r\nmedia=\"ALL\" href=\"../../tutorial.css\" />\r\n</head>\r\n\r\n<body>\r\n<h1>Testing ODBC connectivity from PHP hosted within Virtuoso</h1>\r\n\r\n<hr />\r\n\r\n<?php\r\n# set global variables based on the form thing - see `register global\r\n# variables' and PHP security updates\r\n$query=$_POST['query'];\r\n$uid=$_POST['uid'];\r\n$passwd=$_POST['passwd'];\r\n$listtables=$_POST['listtables'];\r\n$DSN=$_POST['DSN'];\r\n$exec=$_POST['exec'];\r\n?>\r\n\r\n<p>Enter the parameters for your query here:</p>\r\n\r\n<form action=\"odbc-sample.php\" method=\"post\"> \r\n<div> \r\n<span class=\"caption\">DSN</span> \r\n<input type=\"text\" name=\"DSN\" value=\"<?php\r\nprint ($DSN<>\"\")?$DSN:\"Local Virtuoso Demo\"\r\n?>\" /> \r\n\r\n<span class=\"caption\">UserID</span>\r\n<input type=\"text\" name=\"uid\" value=\"<?php print ($uid<>\"\")?$uid:\"demo\" ?>\" />\r\n\r\n<span class=\"caption\">Password</span>\r\n<input type=\"password\" name=\"passwd\" value=\"<?php print ($passwd<>\"\")?$passwd:\"demo\"?>\" />\r\n</div>\r\n\r\n<div>\r\n<span class=\"caption\">Query</span> \r\n<input type=\"text\" name=\"query\" value=\"<?php\r\nprint ($query<>\"\")?$query:\"select top 100 * from Demo..Customers\"\r\n?>\" /> \r\n</div>\r\n<div>\r\n<input type=\"submit\" name=\"exec\" value=\"Execute query\" />\r\nor\r\n<input type=\"submit\" name=\"listtables\" value=\"List Tables\" />\r\n</div>\r\n</form>\r\n\r\n<hr />\r\n\r\n<?php\r\nif($query<>\"\" && $DSN<>\"\" && $exec!=NULL) {\r\n\r\nprint \"<h2>Results:</h2>\r\n\";\r\nprint \"<p>Connecting... \";\r\n$handle=odbc_connect (\"$DSN\", \"$uid\", \"$passwd\");\r\n\r\nif(!$handle) {\r\nprint \"<p>Uh-oh! Failure to connect to DSN [$DSN]: <br />\";\r\nodbc_errormsg();\r\n}\r\nelse {\r\nprint \"done</p>\r\n\";\r\n$resultset=odbc_exec ($handle, \"$query\");\r\nodbc_result_all($resultset, \"border=2\");\r\nodbc_close($handle);\r\n}\r\n}\r\n\r\nif($listtables!=NULL) {\r\nprint \"<h2>List of tables</h2>\";\r\nprint \"<p>Connecting... \";\r\n$handle=odbc_connect (\"$DSN\", \"$uid\", \"$passwd\");\r\nprint \"done</p>\r\n\";\r\n\r\nif(!$handle) {\r\nprint \"<p>Uh-oh! Failure to connect to DSN [$DSN]: <br />\";\r\nodbc_errormsg();\r\n}\r\nelse {\r\n$resultset=odbc_tables($handle);\r\nodbc_result_all($resultset, \"border=2\");\r\nodbc_close($handle);\r\n}\r\n}\r\n?>\r\n</body>\r\n</html>\r\n\r\n\r\n\r\n---++ Concerns and Improvements\r\n\r\n\r\nHistorically, iODBC has not been fully supported in PHP. We made a patch addressing these issues:\r\n\r\n * ODBC 3.52 datatypes are now used, to comply with ODBC64 spec on Win64 and 64-bit *nix platforms\r\n * Enabled use of SQLDriverConnect(), array fetching, and other advanced PHP API functions\r\n * Made the static cursor model the default (instead of dynamic), to speed up advanced drivers. \r\nThe cursor model can be selected by a setting in php.ini.\r\n\r\nThis patch has been incorporated into PHP around version 5.2.11 and above.\r\n\r\nTo use this patch with older versions of PHP, first download it: \r\n[[%ATTACHURLPATH%/iodbc-php5.diff][iodbc-php5.diff]]\r\n\r\nSecond, apply it using patch(1):\r\n\r\n\r\nbash$ tar xvfpj php-5.2.5.tar.bz2\r\nphp-5.2.5/\r\nphp-5.2.5/ext/\r\nphp-5.2.5/ext/gd/\r\nphp-5.2.5/ext/gd/gd.c\r\nphp-5.2.5/ext/gd/gd_ctx.c\r\n...\r\nbash$ patch -p0 < ../iodbc-php5.diff\r\npatching file ext/odbc/php_odbc.c\r\nHunk #26 succeeded at 1644 (offset 1 line).\r\nHunk #27 succeeded at 1715 (offset 1 line).\r\nHunk #28 succeeded at 1777 (offset 1 line).\r\nHunk #29 succeeded at 1863 (offset 1 line).\r\nHunk #47 succeeded at 3603 (offset 1 line).\r\npatching file ext/odbc/php_odbc.h\r\npatching file ext/odbc/php_odbc_includes.h\r\n\r\n\r\nYou can now resume the build process from the \"./configure\" step above.\r\n\r\n\r\n\r\n\r\n---++ References\r\n\r\n * PHP on macOS [[http://www.php.net/manual/en/install.macosx.php][installation instructions]] \r\n * [[http://www.iodbc.org][iODBC.org]] \r\n * History of [[http://www.iodbc.org/odbcstory.htm][ODBC on Unix]] \r\n * [[http://www.php.net/support.php][PHP main site]] \r\n * [[http://www.openlinksw.com/][OpenLink Software]] \r\n * [[http://community.openlinksw.com/][Community Space]]\r\n * [[http://support.openlinksw.com/][Support Center and Case System]]" . . "2016-09-14T12:28:33.942728"^^ . . "IODBCPHPHOWTO" . . . . . . . . "2016-09-14T12:28:33Z" . . "2019-03-20T09:56:21Z" . . . . . . . "2019-03-20T09:56:21.892162"^^ . . . "7b8747350d16225dc5bbfc172a28dd23" . . . .