{"id":16,"date":"2019-12-04T13:50:12","date_gmt":"2019-12-04T18:50:12","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/?p=16"},"modified":"2019-12-04T13:59:37","modified_gmt":"2019-12-04T18:59:37","slug":"connecting-php-to-oracle-with-oci8","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2019\/12\/04\/connecting-php-to-oracle-with-oci8\/","title":{"rendered":"Connecting PHP to Oracle with OCI8"},"content":{"rendered":"<p>Below is the set of steps I took to connect a XAMPP setup to an Oracle database server.  I am doing this on a server running Windows Server 2016.<\/p>\n<ol>\n<li>Download and install XAMPP.  I chose the one bundled with the 32-bit version of PHP 7.3.2 with thread safety.  <a href=\"https:\/\/sourceforge.net\/projects\/xampp\/files\/XAMPP%20Windows\/7.3.2\/\" rel=\"nofollow\" target=\"_sourceforge\">Sourceforge: xampp-win32-7.3.2-0-VC15-installer.exe<\/a><\/li>\n<li>Download and install Oracle Instant Client.  Because the PHP architecture is 32-bit, Oracle Instant Client must also be 32-bit.  Take note of your Oracle server&#8217;s version, and install the appropriate client.  <a href=\"https:\/\/www.oracle.com\/database\/technologies\/instant-client\/microsoft-windows-32-downloads.html\" rel=\"nofollow\" target=\"_oracle\">Oracle: Oracle Instant Client Downloads<\/a><\/li>\n<li>Set up your sqlnet.ora and tnsnames.ora files at %ORACLE_HOME%\\network\\admin\\.  These two files together will tell your Oracle Instant Client how to get to your Oracle server.  Sample sqlnet.ora:\n<pre class=\"code\">NAMES.DEFAULT_DOMAIN = MYDOMAIN.NET\nSQLNET.AUTHENTICATION_SERVICES = (NTS)\nNAMES.DIRECTORY_PATH = (TNSNAMES, ONAMES, HOSTNAME)\n<\/pre>\n<p>Sample tnsnames.ora:<\/p>\n<pre class=\"code\">DB.MYDOMAIN.NET =\n\t(DESCRIPTION =\n\t\t(ADDRESS_LIST =\n\t\t\t(ADDRESS = (PROTOCOL = TCP)(HOST = odbserver3.mydomain.net)(PORT = 1521))\n\t\t)\n\t\t(CONNECT_DATA =\n\t\t\t(SERVICE_NAME = db)\n\t\t)\n\t)\n<\/pre>\n<\/li>\n<li>In Windows, add the folder of Oracle Instant Client to the PATH system variable.  Create a new system variable called ORACLE_HOME and put the same path in there as well.<\/li>\n<li>Download the OCI8 package.  I chose the one labeled &#8220;7.3 Thread Safe (TS) x86&#8221; in order to match my PHP version, thread safe configuration, and the 32-bit architecture.  Once downloaded, extract either php_oci8.dll, php_oci8_11g.dll, or php_oci8_12c.dll (depending on your Oracle server version) and place the DLL file in the PHP Extensions directory.  By default, that folder for my installation of XAMPP is C:\\xampp\\php\\ext\\.  <a href=\"https:\/\/pecl.php.net\/package\/oci8\/2.2.0\/windows\" rel=\"nofollow\" target=\"_php\">PHP PECL: OCI8 for Windows<\/a><\/li>\n<li>Launch XAMPP Control Panel and start the Apache server.  Add phpinfo(); to one of your pages to see if OCI8 has its own section; if so, you are ready to make your connection to your Oracle server.  Here&#8217;s a quick and dirty PHP snippet you can use to do a quick connection test:\n<pre class=\"code\">$conn = oci_connect($user, $password, $server);\n$sql = \"select user from dual\";\n$stid = oci_parse($conn, $sql);\noci_execute($stid);\n$row = oci_fetch_array($stid, OCI_BOTH);\nprint($row[\"USER\"]);\noci_free_statement($stid);\n<\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Below is the set of steps I took to connect a XAMPP setup to an Oracle database server. I am doing this on a server running Windows Server 2016. Download and install XAMPP. I chose the one bundled with the 32-bit version of PHP 7.3.2 with thread safety. Sourceforge: xampp-win32-7.3.2-0-VC15-installer.exe Download and install Oracle Instant &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.dev-notes.com\/blog\/2019\/12\/04\/connecting-php-to-oracle-with-oci8\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Connecting PHP to Oracle with OCI8&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,4],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-oracle","category-php"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":4,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":361,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions\/361"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}