. . "2016-09-14T12:28:33Z" . . "IODBCPHPHOWTOMacOSX" . . . "2016-09-14T12:28:33Z" . . "IODBCPHPHOWTOMacOSX" . . . . . . . . . . . "e4cfcacfe607355352e3d3f365eb4317" . "---+ iODBC-PHP-Apache HOWTO for Mac OS X\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 MacOS X. 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 and 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---++ 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 back end 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. iODBC\r\nis an Open Source Driver Manager maintained by OpenLink Software. It is\r\nreleased under a dual LGPL / BSD license.\r\n\r\n---++ Preface\r\n\r\nYou will also need an ODBC Driver and Database to complete the\r\narchitecture.\r\n\r\nIf you need ODBC drivers to connect to a third-party database on the same\r\nor another machine, OpenLink ODBC Drivers are available, and may be\r\ndownloaded from http://www.openlinksw.com\r\n\r\nThe Virtuoso database may also be downloaded from\r\nhttp://virtuoso.openlinksw.com/\r\n\r\nBoth Virtuoso and OpenLink's Multi-Tier ODBC drivers download with a free\r\n30-day demo license.\r\n\r\nSupport for setting up the OpenLink Drivers may be obtained at\r\nhttp://support.openlinksw.com/\r\n\r\n---++ Overview & Requirements\r\n\r\nFirst, download both php from http://www.php.net/ and the iODBC driver\r\nmanager from http://www.iodbc.org/. Ensure you have any other dependencies\r\nfor PHP installed (for example, mysql, postgresql, imap, libxml etc).\r\n\r\nIf you download a MacOS X binary package of iODBC from the iodbc.org or\r\nOpenLink websites, this will have been built as a framework. This is the\r\nrecommended course of action, as it is compatible with other ODBC-using\r\napplications such as Excel, RealBasic, other packages of PHP for MacOS X,\r\netc. The majority of the rest of this HOWTO assumes you're building from\r\nsource, should you want to customize the process yourself.\r\n\r\n---+++ Building iODBC from source\r\n\r\nIf you are compiling from source, on Macos X, there are two ways whereby a\r\npackage might be compiled - as traditional shared libraries, or as a\r\n`Framework'. If you intend loading php from apache, then it must be\r\ncompiled as a framework. It is also best if you compile iODBC as a\r\nframework as well.\r\n\r\nHaving downloaded the source tarball, unpack it, thus:\r\n\r\n\r\n[oplusmacosx:~/tim] openlink% tar xvfz libiodbc-3.51.1.tar.gz \r\nlibiodbc-3.51.1\r\nlibiodbc-3.51.1/admin\r\nlibiodbc-3.51.1/admin/Makefile.am\r\nlibiodbc-3.51.1/admin/Makefile.in\r\nlibiodbc-3.51.1/admin/acinclude.m4\r\nlibiodbc-3.51.1/admin/config.guess\r\n...\r\n\r\n\r\nIn the libiodbc-3.51.1 directory, read the README.MACOSX file. You will\r\nfind both a ./configure script and a mac/ directory: you can choose the\r\nformer to build a shared library of iodbc, or the latter to make a\r\nframework, thus:\r\n\r\n---++++ Traditional Shared-Library approach\r\n\r\n\r\n[oplusmacosx:~/libiodbc-3.51.1] openlink% ./configure --enable-gui --prefix=$HOME/iodbc-3.51.1-shared\r\n\r\n\r\n(enabling the GUI will require GTK to be installed) - then run `make' and `sudo make install', or\r\n\r\n---++++ MacOS X Framework approach\r\n\r\n\r\n[oplusmacosx:~/libiodbc-3.51.1-shared] openlink% cd mac\r\n[oplusmacosx:~/libiodbc-3.51.1-shared/mac] openlink% make\r\nsh framework-include.sh\r\ncd iODBC; pbxbuild build -buildstyle Deployment\r\n\r\n\r\nIn the latter case, if you wish to install to a non-default location, you\r\nshould amend Makefile in the mac/ subdirectory - search for the line\r\nbeginning `install:', amend the DSTROOT directory and optionally remove the\r\n`sudo' if you're installing it into your user's home directory:\r\n\r\n\r\ninstall:\r\ncd iODBC; pbxbuild install -buildstyle Deployment DSTROOT=$(HOME)/iodbc\r\ncd iODBCinst; pbxbuild install -buildstyle Deployment DSTROOT=$(HOME)/iodbc\r\n\r\n\r\nthen you can run `make install'.\r\n\r\n---++ Building PHP with iODBC\r\n\r\nObtain and unpack the sources for php, e.g. with:\r\n\r\n\r\n[oplusmacosx:~/tim] openlink% bzcat < php-4.3.3.tar.bz2 | tar xvf -\r\nphp-4.3.3\r\nphp-4.3.3/build\r\nphp-4.3.3/build/build.mk\r\nphp-4.3.3/build/build2.mk\r\nphp-4.3.3/build/buildcheck.sh\r\nphp-4.3.3/build/config-stubs\r\n...\r\n\r\n\r\nIf you built iODBC as a shared library earlier, building PHP against it is\r\na simple matter of running configure with a point to the top directory\r\nwhere iODBC was installed:\r\n\r\n\r\n[oplusmacosx:~/php-4.3.3] openlink% ./configure --with-iodbc=$HOME/iodbc-shared && nice make\r\n\r\n\r\nHowever, if you built iODBC as a framework, it's a bit more complicated.\r\nPHP has no support for iODBC as a framework out of the box, so you need to\r\nconfigure it first and then edit the generated Makefile. A complete\r\nrecommended set of configure options for PHP is:\r\n\r\n\r\n./configure \\\r\n --prefix=/Library/PHP4 \\\r\n --with-openssl=/usr \\\r\n --with-zlib=/usr \\\r\n --enable-calendar \\\r\n --enable-exif \\\r\n --enable-ftp \\\r\n --enable-mbstring \\\r\n --disable-mbregex \\\r\n --enable-session \\\r\n --enable-sockets \\\r\n --enable-tokenizer \\\r\n --enable-wddx \\\r\n --with-xml \\\r\n --enable-yp \\\r\n --enable-versioning \\\r\n --enable-trans-id \\\r\n --enable-track-vars \\\r\n --with-mysql \\\r\n --with-ldap=/usr \\\r\n --with-iodbc=/usr \\\r\n --with-jpeg-dir=/Library/PHP4 \\\r\n --with-png-dir=/Library/PHP4 \\\r\n --enable-xslt \\\r\n --with-xslt-sablot=/Library/PHP4 \\\r\n --with-pdflib=/Library/PHP4 \\\r\n --with-tiff-dir=/Library/PHP4 \\\r\n --with-pgsql=/Library/PHP4 \\\r\n --with-iconv=/Library/PHP4 \\\r\n --with-sybase=/Library/PHP4 \\\r\n --with-mcrypt=/Library/PHP4 \\\r\n --with-curl=/Library/PHP4 \\\r\n --with-freetype-dir=/Library/PHP4 \\\r\n --with-ttf=/Library/PHP4 \\\r\n --with-xmlrpc \\\r\n --enable-mime-magic \\\r\n --without-pspell \\\r\n --with-expat-dir=/Library/Apache2 \\\r\n --with-t1lib=/Library/PHP4 \\\r\n --enable-dbx \\\r\n --without-pcre-regex \\\r\n --without-pgsql \\\r\n --enable-shared \\\r\n --enable-cli \\\r\n # --with-apxs2=/Library/Apache2/bin/apxs \r\n\r\n\r\nNote that if you enable the cli (as would make sense for testing) you\r\nshould disable support for apxs, otherwise duplicate symbols may result -\r\nchose one or the other.\r\n\r\nNow, edit the Makefile, and search for references to iodbc. You need to\r\nreplace these lines:\r\n\r\n\r\nODBC_INCLUDE = -framework iODBC -F /Users/openlink/iodbc-mac/Library/Frameworks/\r\nODBC_LIBS = -framework iODBC -F /Users/openlink/iodbc-mac/Library/Frameworks/\r\nODBC_LFLAGS = -framework iODBC -F /Users/openlink/iodbc-mac/Library/Frameworks/\r\n\r\n\r\nRemove the first two words on the right side of this line:\r\n\r\n\r\nEXTRA_LDFLAGS = -export-symbols \\\r\n/Users/openlink/php-4.3.3/sapi/apache2handler/php.sym \\\r\n-L/Library/PHP4/lib \\\r\n-L/Users/openlink/iodbc-mac//Library/Frameworks/iODBC.framework/lib \\\r\n-L/Library/Apache2/lib\r\n\r\n\r\n(the `-export-symbols' and path to `php.sym')\r\n\r\nReplace the EXTRA_LDFLAGS line accordingly:\r\n\r\n\r\nEXTRA_LIBS = -lsablot -lexpat -lexpat -lexpat -lsybdb -lpdf -lz \\\r\n-ltiff -lpng -ljpeg -liodbc -lmcrypt -lltdl -lldap -llber -liconv -lcurl \\\r\n-lz -lssl -lcrypto -lm -ldl -lcurl -lz -lssl -lcrypto -lz -liodbc\r\nEXTRA_LDFLAGS = -L/Library/PHP4/lib \\\r\n-L/Users/openlink/iodbc-mac//Library/Frameworks/iODBC.framework/lib \\\r\n-L/Library/Apache2/lib\r\nEXTRA_LIBS = -lsablot -lexpat -lexpat -lexpat -lsybdb -lpdf -lz -ltiff \\\r\n-lpng -ljpeg -lmcrypt -lltdl -lldap -llber -liconv -lcurl -lz -lssl \\\r\n-lcrypto -lm -ldl -lcurl -lz -lssl -lcrypto -lz -framework iODBC\r\n\r\n\r\nFinally, ensure there are no further references to `-liodbc' in the Makefile, before typing `make'.\r\n\r\n---+++ Testing a PHP CLI works\r\n\r\nIt's advisable to build PHP as a CLI before going the whole way and testing with apache. To test that PHP is working with iODBC you can do something like:\r\n\r\n\r\n[oplusmacosx:~/php-4.3.3] openlink% echo '<?php echo \"foo\r\n\"; odbc_connect(\"foo\",\"username\",\"pwd\");?>' | ./sapi/cgi/php\r\nContent-type: text/html\r\nX-Powered-By: PHP/4.3.3\r\nfoo\r\n<br />\r\n<b>Warning</b>: odbc_connect(): SQL error: [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded, SQL state IM002 in SQLConnect in <b>/Users/openlink/php-4.3.3/-</b> on line <b>1</b><br />\r\n\r\n\r\nThe fact that the DSN `foo' is not found is immaterial; what matters here\r\nis that it's iODBC emitting a standard error message, showing PHP and iODBC\r\nare talking together. (If iODBC had not been included, you would have an\r\nerror message about an attempt to call an undefined function\r\n`odbc_connect', instead).\r\n\r\nYou can double-check that the framework version of iODBC is in use by\r\nrunning the above command through `otool -l' and grep-ing the output for\r\niodbc. If you see, for example, /usr/lib/libiodbc in there, you know it's\r\nusing the shared-library version instead.\r\n\r\n\r\n[oplusmacosx:~/php-4.3.3-shared-usr] openlink% echo \\\r\n'<?php echo \"foo\r\n\"; odbc_connect(\"foo\",\"username\",\"pwd\");?>' \\\r\n| otool -l ./sapi/cgi/php | grep -i iodbc\r\nname /usr/lib/libiodbc.2.1.6.dylib (offset 24)\r\n\r\n\r\n---++ Integrating with Apache\r\n\r\nIf you've used the CLI mode as a test above, you will need to reconfigure\r\nand rebuild PHP using --disable-cli and --with-apxs2=/path/to/apxs.\r\n\r\nOnce PHP is built with all your required configure options against a\r\nframework iODBC, it should be sufficient to execute `make install' for it\r\nto invoke apxs, which will place suitable directives in apache's\r\nhttpd.conf:\r\n\r\n\r\n# PHP4 configuration\r\nLoadModule php4_module modules/libphp4.so\r\nAddType application/x-httpd-php .php\r\nAddType application/x-httpd-php-source .phps\r\n\r\n\r\nYou should restart the apache webserver when these directives are in place,\r\nand run a simple test-script to see how PHP is being loaded, and attempt a\r\nsimple database connection:\r\n\r\nphpinfo.php:\r\n\r\n\r\n<?php phpinfo(); ?>\r\n\r\n\r\nand...\r\n\r\n\r\n<?php\r\n\r\n#Set up environment variables\r\nputenv(\"DYLD_LIBRARY_PATH=/path/to/odbcsdk/lib\");\r\nputenv(\"ODBCINSTINI=/path/to/odbcinst.ini\");\r\nputenv(\"ODBCINI=/path/to/odbc.ini\"); //odbc.ini contains your DSNs.\r\n\r\n$dsn=\"DSN_NAME\"; \r\n$user=\"username\";\r\n$password=\"password\";\r\n\r\n$sql=\"SELECT * FROM table\";\r\n\r\n// directly execute mode\r\nif ($conn_id=odbc_connect(\"$dsn\",\"\",\"\")) {\r\necho \"connected to DSN: $dsn\";\r\nif($result=odbc_do($conn_id, $sql)) {\r\necho \"executing '$sql'\";\r\necho \"Results: \";\r\nodbc_result_all($result);\r\necho \"freeing result\";\r\nodbc_free_result($result);\r\n}else{\r\necho \"can not execute '$sql' \";\r\n}\r\necho \"closing connection $conn_id\";\r\nodbc_close($conn_id);\r\n}\r\nelse{\r\necho \"can not connect to DSN: $dsn \";\r\n}\r\n?>\r\n\r\n\r\n---++ References\r\n\r\n * MacOS X PHP [[http://www.php.net/manual/en/install.macosx.php][installation instructions]] \r\n * phpmac.com [[http://www.phpmac.com/][site deditcated to PHP on the Mac]] \r\n * [[http://www.iodbc.org][http://www.iodbc.org]] \r\n * History of [[ODBCOnUnix][ODBC on Unix]] \r\n * [[http://www.php.net/support.php][PHP main site]] \r\n * [[http://www.openlinksw.com/][OpenLink Software]] - [[http://www.openlinksw.com/support/suppindx.htm][Support]] , [[http://www.openlinksw.com/support/teclinks.htm][links]] and [[http://www.openlinksw.com/info/docs/odbcwhp/tableof.htm][white-papers]] \r\n " . "IODBCPHPHOWTOMacOSX" . . . . . . . . . "2016-09-14T12:28:33.901960"^^ . . . . "2016-09-14T12:28:33.901960"^^ . .