Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Informix and PHP

316 views

Published on

  • Login to see the comments

  • Be the first to like this

Informix and PHP

  1. 1. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 1 | P a g e Adding Informix support to an existing PHP development environment Beingan IBMer andhavingusedLinux,Apache,MySql andPHP(LAMP) fairlyextensivelyoverthe last decade or so,I decidedthe otherdaythat I wantedtodo some PHPdevelopmentusingInformixinstead of MySql. I lookedtothe Internetforinstructionsonhow toenable InformixwithmycurrentLAMP developmentenvironmentandwasa bitsurprisedthatI didn’tsee instructionsonhow toplugInformix intoan existingPHPenvironment. BeingaproblemsolverIwasdeterminedtofigure thisout. Itonly occurredto me afterI solvedthisparticularpuzzle thatotherfolksmayhave the same questionand wouldlike toknowhowtogo about addingInformix totheircurrentPHPenvironmenttoo. This documentwill describe the stepsneededforaddingInformixtoyourPHPenvironment. Prerequisites There are a few thingsyouneedtogetstartedwiththis. ObviouslyyouneedaLAMP,WAMP (Windows, Apache,MySql,andPHP),or otherApache and PHPdevelopmentsystem. Youwill alsoneedthe PDO_Informix PECLpackage and,of course,an Informix database instance toworkwith. I’ll gothrough the stepsI performedforsettingupmyPHP/Informixdevelopmentsystemfromscratchto illustrate howto make thiswork. You’ll justneedtodeterminewheretostartin thisprocessif youalreadyhave parts of thisin place. Getting Started I builtmydevelopmentsystemusingRedHatEnterprise Linux 5 64-biton a virtual machine using VMWare Workstation10. AlthoughIuseda virtual machine,Icouldhave createda new hard drive partition,installedLinuxinthatpartition,andmodifiedmycomputertoallow dual-bootintoLinux as well. You can also buildthisenvironmentusingWindows. Theyonlydifferencewillbe the install methodsforthe products. It reallydoesn’tmatterhow youhostthe operatingsystem. RedHatisa specificvendorimplementationof Linux sothese instructionsshouldhelpyouwithotherversionsof Linux as well. Once I had my Linux desktopupandrunning,Ithenneededafew othersoftware packagestohelpme move forwardwithbuildingmyenvironment. MostLinux versionscome withApache butitmaynot be installedaspartof the base operatingsystemconfiguration. Mysystemdidnothave Apache installed so I had to start fromthere. I like quickandeasyas longas it islegal andcomplete. Giventhis,Ichose touse XAMPPto helpme with the installationof the Apache webserveralongwithPHP,Perl,andMySql (eventhoughIdon’tneedthis component). XAMPPisapreconfigured,opensource PHPdevelopmentenvironmentthatprovidesa verynice install forall the components. Of course,youcanget eachcomponentindividuallyandinstall themseparatelyif youwish(andI’ve done thatmanytimesinthe past),butI wantedtoget thisdone quicklysoI chose the XAMPProute for easyinstallation.
  2. 2. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 2 | P a g e To get startedwithXAMPP, logintoyourLinux systemasroot, opena browserandnavigate to http://www.xampp.org. Onthe mainpage (at leastas of thiswriting),there isanoptiontodownload XAMPPfor Windows,XAMPPforLinux,andXAMPPforOS X. Clickonthe linktodownloadXAMPPfor Linux andyour browsershouldautomaticallystartdownloadingthe install package. If,forsome reason, the Linux browsercan’topenthe XAMPP.orgmainpage (redirectstoapachefriends.org),thenthe XAMPPpackage can alsobe obtainedfromSourceForge.net(whichiswhatIhad to do). For the Linux package,itis namedsomethinglike xampp-linux-x64-5.6.11-1-installer.runorsomethingsimilar(the numbersmaybe different –noworries). My downloadplacedthe fileonmyLinux desktop,however,it may be placedina differentlocationonyoursystemdependingonthe downloadlocationsettingsfor your browser. The firstchallenge Iencounterediswhattodowiththisdownloadedfile. Since the .runextensionon the file isnota commonlyknownextension,Linux reallydoesn’tknow whattodowithit. Beingold school,I openeda terminal window toinvestigate thisfurther. Itturnsout the downloadedfileisan executable butitdoesn’tdownloadwiththe correctfile permissions toexecuteit. If youaren’tfamiliar withLinux file permissions,justfollowthesestepsanddon’tgetconcernedoverit. Fromthe terminal window,Ichangeddirectorytomydownloadlocation(/root/Desktop) andlistedthe filetolookatthe currentpermissions. Itshouldlooksomethinglikethe following: Figure 1 - examining XAMPP file permissions The permissionsforthe file are indicatedinthe first10 characters of the file listing. Inthiscase,the ownerof the file (root) hasreadand write permissions,the groupmembers(root) have read permissions,andeveryone else hasreadpermissions. Inorderto execute thisfileasaninstall program we needtoadjustthese permissions. The image below showsyouhow tomake thisan executablefile:
  3. 3. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 3 | P a g e Figure 2 - changing XAMPP*.run file permissions Don’tworry if youdon’tknowexactlywhathappenswiththe ‘chmod’command. Youcan see the permissionshave changedonthe file anditcan now be run as an executable program. Atthispointwe wantto run the program. The followingfigureshowshow torunit: Figure 3 - XAMPP installation
  4. 4. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 4 | P a g e Followthe installationwizardpromptsto install XAMPPonyoursystem. If youchose the defaults,the install programwill installthe productsinthe /opt/lamppdirectory(onLinux)orinC:xampp(on Windows). Aspartof the installationprocess,XAMPPwill startthe Apache webserver. However,the install scriptdoesnotmodifythe systemstartupscriptssothatApache (andthe otherprograms) will restartwhenthe systemisshutdown. Itisveryeasyto start/stop/restartXAMPPonLinux. Opena terminal andchange directoryto/opt/lampp (orthe install directoryif youchose somethingdifferent duringthe initial install). The directorywill looksomethinglike the following: Figure 4 - /opt/lampp directory listing The greenfilenamesinthe directorylistingare executables. TostartApache and MySql,justtype ‘/opt/lampp/lamppstart’onthe commandline. To stopApache and MySql,justtype ‘/opt/lampp/lamppstop’onthe commandline. There are otheroptionstoowhichcan be listedby typing/opt/lampp/lamppwithoutanyparameters. The commandwill displaythe availableoptions. As a final checkforthe installation,openawebbrowserandopen http://localhost. Youshouldsee the followingif XAMPPwasinstalledcorrectly andeverythingisrunningcorrectly.
  5. 5. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 5 | P a g e Figure 5 - XAMPP start page Once you have XAMPPinstalled,youwill now be able todevelopPHPapplications. The directorywhere all the webpagesfor yourlocal serverare foundis/opt/lampp/htdocs –alsoknownasthe DocumentRootdirectoryforyourwebserver. Ialwaystestmyinstallationtoensure PHPisrunningand workingcorrectlybycreatinga simple test.phpfileinthe /op/lampp/htdocsdirectory. Myfile usually lookslike the following(Ishowthe file openwithvi): Figure 6 - test.php Once you create and save the file,openyourwebbrowserto http://localhost/test.php andyoushould see the followingoutput(justthe topisshown).Thisinformationwill be veryuseful aswe workon installingthe Informix databasemodules.
  6. 6. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 6 | P a g e Figure 7 - output of test.php (phpinfo) Nowthat we have a workingweb server(Apache) andPHPwe canmove on to gettingInformix setupto workwithit. Download and Install Informix If you alreadyhave a workingApache andPHPenvironment,installingthe Informix engine orClient Software DevelopmentKit (CSDK) maybe the correctstartingpointforyour particularsituation. With my developmentbuild,IdecidedIwantedthe Informix database enginetorunlocallyonmy developmentserver. Havingthe Informix database enginelocallyinstalledisconvenientfordeveloping Informix basedapplicationssince Ihave control of database objects(databases,tables,views,indexes, storedprocedures,etc…) andcan make changesto anyof these objectsquicklyduringthe development lifecycle. If youare workingwithanexistingInformix database locatedonadifferentserver,the only componentyouwill needisthe Informix ClientSoftware DevelopmentKit. Informix isafull-featured,enterprise capable database productandcomesinseveral different bundles or packages. For my simple developmentenvironmentIuse the Informix Innovator-CEditionsince itis free todownloadfromIBM. AnyapplicationsIdevelopthataccessInformix Innovator-CEdition will workwithany of the otherInformix editionswithoutanymodificationsorchanges,sousing Innovator-C Editionfora developmentenvironmentisagreat wayto get started. Justto be complete,Ishouldpoint out that the Informix DeveloperEditionisalsoafree productand will workfordevelopmentpurposesas well. In additiontoinstallingthe Informix database engine,youwillalsowanttoinstall the Informix Client Software DevelopmentKit. The CSDKhasthe librariesneededforPHPtorun the PDO_Informix plug-in. We’ll deal withthe CSDKandhowto set that upafterwe getthe Informix database installed. Imention the CSDK aheadof time because youmightas well downloaditwhile youare onthe IBMwebsite to downloadthe Informix databaseengine. Informix software downloadsare available from the IBMInformix website athttp://www- 01.ibm.com/software/data/informix/download.html. Youwill see linkstoboththe Developerand
  7. 7. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 7 | P a g e Innovator-Ceditions(no-charge database)aswell as90-daytrialsfor boththe Informix Enterprise EditionandInformix AdvancedEnterpriseEdition. Below the Informix databasessection,youwillalso see a linkforthe Informix ClientSoftware DevelopmentKit(CSDK). Downloadboththe database and the CSDK to yourXAMPP server. You shouldhave twocompressedarchive fileswhenthe downloadis complete. AsImentionedbefore,mysystemplacesdownloadedfilesonmydesktopandthe image belowshowsyouwhatthe downloadedpackageslooklike. Figure 8 - Informix software packages (on the desktop) Both the Informix database andthe CSDKare downloadedasarchive filesintape archive (tar) format. In orderto access the filesinthe archive we needtoextractthem. Since Idon’twant all the Informix files placedonmy desktop,Icreate a folder,copythe archive to the folder,andextractthe files. The stepsI take to do that are illustratedinFigure 9:
  8. 8. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 8 | P a g e Figure 9 - extracting and starting the Informix database install Once the filesare extractedyouwill see the ids_install (IDSstandsforInformix DynamicServer) commandin the directorylisting. Since the currentdirectoryisnotinmy currentsystempath,I start the install usingthe command“./ids_install–i gui”whichwill invokethe graphical userinterface (thereisa console andsilentinstalloptiontoobutIwon’tcoverthat here). Follow the promptsinthe GUI to complete the install. Also,allowthe installscripttocreate yourInformix instance foryousoyouwill have a workingdatabase serverwhenthe install iscomplete. Also,the GUIwill promptyoutoopena terminal window toaccessthe database whencomplete. Repond‘yes’toopenthisterminal soyoucan verifythe installation. IinstalledmyInformix databasetothe /opt/informix directory. Iwill use this locationthroughoutthe remainderof thisdocument. Make note of the passwordyoucreate forthe Informix usersince youwill needthatlater. Once the database installationiscomplete,repeatthe processforthe CSDKarchive file. Use the ‘installclientsdk’commandinsteadof the ‘ids_install’command. Followthe GUIpromptsto complete the installation. Note:some distributionsof the Informixengine come withthe CSDKincluded inthe package. If the CSDKinstallationdiscoversanexistingCSDKalreadyinstalled,youcanabort or cancel the install since youalreadyhave all the componentsyouneedforInformix. The last stepinthe Informix installation isverifyingthe installationof the database. If youopenedthe terminal window duringthe Informixengine install (ids_install process),the correctenvironment variableshave beensetwithinthe terminal toenable accesstoInformix. Checkthe installationby typing‘onstat–‘ at the terminal windowcommandprompt. Youroutputshouldlooklike the following:
  9. 9. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 9 | P a g e Figure 10 - verify the Informix installation As the image shows,InformixDynamicServer(myversion - 12.10) iscurrentlyonline. Thismeans Informix isrunningandsharedmemoryisinitializedforthe database instance. We are now ready for the nextstepof the process. PHP and Informix – PDO_Informix module There are a fewpre-requisitesforaddingPDO_Informixtothe PHPconfiguration. First,yoursystem needstohave a compiler– usuallyGCCor CC – installed. Forthe RedHatserverI usedformy server,the compilerwasinstalledaspartof the initial operatingsystem. Manyversionsof Linux will have the compilerautomaticallyinstalledaspartof the operatingsysteminstall,however,youshouldcheckyour Linux servertobe sure. Anothercritical componenttoinstallingPDO_Informix isthe PHPDevelopmentcomponents. If you installedXAMPP(orLAMPPonLinux),thenthisPHPextensionwasinstalledaspartof the package. If youinstalledPHPusinganothermethod,youwill have tocheckyourPHPinstall tosee if thisextension was included. Specifically,we will needthe command‘phpize’tocreate the pdo_informix.solibrary. If youare uncertain,doa quickfilesystemcheckforthe ‘phpize’command. Iuse the command‘find/ - name phpize –print’froma terminal tolocate the file. If youcan’tfindthe commandyou will needto downloadthe PHPDevelopmentpackage fromthe Internetandinstall itaccordingtothe instructions. One itemto mentionissome PHPinstallationsincludePEARandPECL. If you have PEARand PECL installed,youcaninstall PDO_Informix using‘peclinstallpdo_informix’fromaterminal. If there are any missingdependencies,the commandwillinformyouwhatismissing. Iwon’tgo intoPEARand PECL install since those applicationsare well documentedonthe Internet. So,for the RedHat server,Ididnot have PEARor PECL available soinstallingthe PDO_Informix extension takesa bit of work. The firstitemonour lististo downloadthe PDO_InformixPECLpackage fromthe PECL repositoryonthe Internet. Usingyourfavorite searchengine, simplysearchforPECL PDO_Informix. Asof thiswriting,the PDO_Informix package islocatedat
  10. 10. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 10 | P a g e https://pecl.php.net/package/PDO_INFORMIX withacurrentversionof 1.3.1. Downloadthe PDO_INFORMIX-1.3.1.tgzbyclickingonthe linkinthe download sectionof the page. Since the PDO_Informix package isanextensionof PHP,the correctplace to place the filesinthe package is inthe PHP extensionsdirectory. FormyLAMPP install,the directorywhere PHPextensions are storedis/opt/lampp/include/php/extsothatis where Iextractedthe PDO_Informix archiveI downloadedfromthe PECLrepository. If youare unsure of where the extensionstoyourPHPserver are locatedjustlookforany of the installedpackages(GDisa goodone since itisthe extensionthat allowsthe servertoworkwithimagesandit isextremelycommoninPHPinstalls). Use the find commandto locate one of the installedextensionsanditwill show youwhere toplace the PDO_Informix extractedfiles. Figure 11 showsyouhow to find,move andextractthe PDO_Informix package in the PHPextensionsdirectory. Figure 11 - finding the extension directory and unpacking PDO_Informix As youcan see,the package containsfilesthatrequire youtocompile the programwithaC compiler. Thisisn’toverlydifficult. However,thereisacritical stepto compilinganythingforInformix thatmany of the instructionsonthe Internetoverlook. Inorderto compile PDO_Informix,the compilerneedsto knowwhere the appropriate Informix librariesare located. Also,PHPneedstoknow somethingabout the Informix environmentinordertoworkwiththe installeddatabase engine. Thisisall accomplished throughenvironmentvariables. So,let’sgetthose setup. Whenyou installedInformix (probablyinthe /opt/Informixdirectory),the install programcreatedsome sample shell scriptsthatsetthe appropriate environmentvariables. Figure 12showsthe directory listingof /opt/Informix,the shell scriptsthatwere created (withabox aroundthem),anddisplaysthe environmentvariablesthatare set(forthe K-Shell script):
  11. 11. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 11 | P a g e Figure 12 - scripts for setting Informix environment variables Since I use the BASH shell,Ihave tosetthe environmentvariablesexactlyasshownabove (if youare usingthe C-Shell youwoulduse the ol_informix1210.cshfile). Asageneral rule,Ieitheraddthese globally (mostLinux systemuse /etc/profile forsettingglobal environmentvariables) soall userswill have themsetautomatically(if itisa sharedserverandmultiple people are usingit) orI addthe INFORMIXDIR,INFORMIXSERVER,ONCONFIG,INFORMIXSQLHOSTS,GL_USEGLU, and PATH environment variable settingsshownabove tomylocal .bash_profilesothatmy local account will automaticallyset these whenIlogin. Inthiscase, I editedthe .bash_profile in$HOME (formy rootaccount) andalso editedthe .bash_profileforthe Informix useraccount. Withthese environmentvariablesset,youcan type any of the Informix command(onstat,oninit, onmode, onspaces,ontape,etc…) directlyfroma terminal commandline andtheywill work,regardlessof yourcurrentdirectory. There isone more extremelyimportantenvironmentvariable thatisrequiredforcompilinganything Informix related (oranyotherClibraryadditionsforthatmatter). Thisenvironmentvariableisthe LD_LIBRARY_PATH. If you checkthe http://localhost/test.php webpage,youwillfindthisenvironment variable inthatlisting,however,therewon’tbe anythingInformixrelatedassociatedwithit. We need to fix thisif PHPis goingto be able to use Informix. So,the challengeis –where dowe set this environmentvariablesothatPHP can use it? Well,since PHPisrunningwithinthe Apache webserver, we have to setthe environmentforthe webservertoinclude thisvariable. If youusedXAMPP(LAMPP) to install the Apache webserverwithPHP,the startupscriptswill lookforanyadditionalenvironment variablesinthe /opt/lampp/bin/envvarsfile. If youare notsure where additional environmentvariables can be setfor yourApache/PHPstartup,youcan examine the startupscriptstofindit. Figure 13 shows the part of the apachectl shell script(locatedin/opt/lampp/bin) thatloadsadditional environment variables. Ifoundthe apachectl shell scriptbyexaminingthe lamppstartupscript(/opt/lampp/lampp) and findingthe commandtostart the Apache webserver.
  12. 12. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 12 | P a g e Figure 13 - apachectl shell script environment variables section Since the apachectl scriptisspecificallylookingforthe envvarsfile inthe /opt/lampp/bindirectory,all we needtodo is addthe necessaryenvironmentvariablestothisfile. Figure 14showsthe contentsof the envvarsfile. Ialsoensure the INFORMIXDIRenvironmentvariable issetforApache/PHP since many of the entriesinthe LD_LIBRARY_PATHreferto it.
  13. 13. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 13 | P a g e Figure 14 - contents of the /opt/lampp/bin/envvars file In orderfor these changestotake effect,youwill needtorestartthe Apache webserver. Use the command‘/opt/lampp/bin/apachectl restart’torestartApache. AftersuccessfullyrestartingApache, the outputof http://localhost/test.php will show the changestothe LD_LIBRARY_PATH(figure 15). Figure 15 - LD_LIBRARY_PATHafter restart
  14. 14. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 14 | P a g e Nowthat we knowhowto setthe LD_LIBRARY_PATH variable,itwouldbe goodtoknow whatto include inthe LD_LIBRARY_PATH to ensure everythingworkscorrectly. InFigure 14, part of the LD_LIBRARY_PATH includescomponentsof the OpenAdminTool (OAT) whichinstallsitsownweb serveras part of the install process. If youare usingOAT,youwill wantto keep these directoriesinthe LD_LIBRARY_PATH. For our installation,we onlyneedtoinclude the followingaspart of the LD_LIBRARY_PATH (rememberwe setthe $INFORMIXDIRenvironmentvariable to/opt/Informix): $INFORMIXDIR/lib $INFORMIXDIR/lib/cli $INFORMIXDIR/lib/esql $INFORMIXDIR/incl $INFORMIXDIR/incl/cli $INFORMIXDIR/incl/esql /lib(if notalreadyset) /usr/lib(if notalreadyset) /usr/local/lib(if notalreadyset) Followthe syntax inFigure 14 to setthe LD_LIBRARY_PATH for yourserverenvironment. Nowthat we have setall the environmentvariables,we canfinallymove ontocompilingthe PHP PDO_Informix extension. Openaterminal windowandchange the directorytothe locationwhere you unpackedthe PDO_INFORMIX-1.3.1.tgzfile. Execute the followingcommands: If your phpize commandislocatedina differentdirectorythan/opt/lampp/bin,thensubstitute that directoryinyourpath. The outputof the phpize commandwill looksimilartoFigure 16: Figure 16 - output of phpize command The ./configure commandwill produce several pagesof informationasitchecksto ensure necessary componentsare available. Whenthe commandcompletesyou’llsee anoutputsimilartoFigure 17 and you’ll see config.status:creating config.h: exportPATH=/opt/lampp/bin:$PATH phpize ./configure make
  15. 15. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 15 | P a g e Figure 17 - end of configure command output The last commandinthe sequence isthe make command. ThiscommandtellsLinux to“make”or compile all the applicablefilesintoasharedlibrarythatcan be usedby PHP. Just like the configure command,make producesseveral pagesof informationasthe compilationtakesplace. The final output will looksimilartoFigure 18: Figure 18 - make command output (last page) As youcan see inFigure 18 (nearthe top),the compiledlibraryfilesare placedinthe /opt/lampp/include/php/ext/pdo_informix/modulesdirectory. If we lookat the directorylistingyouwill see the resultsinFigure 19:
  16. 16. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 16 | P a g e Figure 19 - pdo_informix.so shared library The file we needtoallowPHPto connectto Informix database isthe pdo_informix.solibraryfile. The final stepswe needtotake are puttingthisfile inthe extensionsdirectoryandenablingthe extension withinPHP. Enabling the PHP Extension Goingback to http://localhost/test.php webpage,we canfindthe directorywhere PHPlooksforall the currentextensions. Thisdirectoryislistedasthe extension_direnvironmentvariable. Whenyoufindit inon the webpage (see Figure 20),take note of the directory – we will needitforinstallingthe pdo_informix.sosharedlibrary. Figure 20 - PHP extension_dir location For my installation,Isimplycopythe pdo_informix.sofilefromitscurrentlocation (/opt/lampp/include/php/ext/pdo_informix/modules)tothe PHPextensiondirectory (/opt/lampp/lib/php/extensions/no-debug-non-zts-20131226) using: cd /opt/lampp/include/php/ext/pdo_informix/modules cp pdo_informix.so /opt/lampp/lib/php/extensions/no-debug-non-zts-20131226
  17. 17. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 17 | P a g e Next,we needtomodifythe PHPsettingsinphp.ini toenable the extension. Todetermine where the currentphp.ini file islocated,we canagainlookat the http://localhost/test.php webpage. The current configurationfileislistedinthe topof the phpinfo() output(seeFigure 21). Figure 21 - current php.ini file location From a terminal window,we canuse ‘vi’toeditthe php.ini file oryoucanuse a texteditorof your choice. You will notice thatthe php.ini file isquite lengthyanditisorganizedintosections. Youwill needtofindthe DynamicExtensionssectionandenterthe following2linestothe file: Your entrieswill looksomethinglike Figure22 (below): extension=”pdo_informix.so” extension=”pdo_dblib.so”
  18. 18. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 18 | P a g e Figure 22 – adding extensions to the php.ini file Once you have completed the editsandsavedthe file,youwill needtorestartthe Apache webserver againto allowPHPto loadthe dynamicextension. Simplyissue arestartcommandas described previously. If everythinghasworkedproperly,the new pdo_informix dynamicextensionwill be enabledandthe phpinfo() outputwill show the extensionloadedandavailable(Figure23):
  19. 19. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 19 | P a g e Figure 23 - pdo_informix installed, loaded, and enabled
  20. 20. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 20 | P a g e Of course,itisalwaysgoodpractice totest yourwork andwe do thisby creatinga simple PHPpage that accessesourInformix database server. Ensure thatthe Informix serverisrunningusingonstat(you shouldsee itonline) andthensave the followingcode inaphpfile under/opt/lampp/htdocs: Of course,there isalwayssomethingelseyouneedtodoto getcopied code to workon your specific server. Inthiscase, youneedtofindthe service numberforthe Informix database engineandchange <Informix password>tothe actual Informix user’spassword. Tofindthe service numberforyour Informix database engine simplytype the followingatthe commandline: <html> <head> <title>Informix PDOTest</title> </head> <body> <?php try { $db = new PDO("informix:host=localhost;service=<Service>;database=sysmaster;server=ol_informix1210;proto col=onsoctcp;EnableScrollableCursors=1;","informix","<Informix password>"); print"ConnectionEstablished!nn"; $stmt = $db->query("select* fromsystables"); print("<table><tr><th>Table Name</th><th>Owner</th><th>PartNumber</th><th>Table ID</th></tr>"); foreach($stmtas $row){ print("<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td></tr> "); } print("</table>"); } catch (PDOException$e) { print("Error!:" .$e->getMessage() ."<br/>"); die(); } ?> </body> </html>
  21. 21. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 21 | P a g e You shouldsee somethingsimilartothe following(Figure 24): Figure 24 - finding the Informix database server port number For my Informix server,the servicenumberis30503. Yours will probablybe different. Justmake sure youchange <Service>tothe actual numberforyour server. If youdon’tget anyresultsfromrunning thiscommand,thenyourDBA probablyuseda non-standardservice name forthe Informix install. You can modifythe commandto justlookforInformix (cat/etc/services|grepInformix) andsee if thatgives youresults. If not,ask your Informix DBA forthe port numberforyour Informix engine. Now,forthe momentof truth. Openthe php file (Inamedmine test_ifx.php) inawebbrowsertosee if youcan connectto Informix,queryadatabase,andreturnresults. If successful,youroutputwill look like the following: cat /etc/services|grep ol_informix
  22. 22. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 22 | P a g e Figure 25 - successful output from test_ifx.php Conclusion AddingInformix databasesupporttoyourexistingPHPenvironmentisfairlystraightforwardonce you’ve identifiedall the necessarycomponentsandinstalledthem. Aswithmostserversandsystems, there are variationsinarchitecture anddirectorystructure whichmayrequire youtoalterthese instructions. Withalittle researchandusingavailableresourcessuchasIBMDeveloperworks,you’ll be able to adjustforthese differencesandgetthe mostoutof yourInformix PHPenvironment.
  23. 23. DavidA. Bernhardt IBM Technical SalesSpecialist October2, 2015 23 | P a g e Appendix A – List of Figures Figure 1 - examining XAMPPfile permissions........................................................................................2 Figure 2 - changing XAMPP*.run file permissions..................................................................................3 Figure 3 - XAMPP installation...............................................................................................................3 Figure 4 - /opt/lampp directorylisting..................................................................................................4 Figure 5 - XAMPP start page................................................................................................................5 Figure 6 - test.php ..............................................................................................................................5 Figure 7 - output of test.php (phpinfo).................................................................................................6 Figure 8 - Informix software packages (on the desktop) ........................................................................7 Figure 9 - extracting and starting the Informix database install..............................................................8 Figure 10 - verify the Informix installation............................................................................................9 Figure 11 - finding the extension directory and unpacking PDO_Informix.............................................10 Figure 12 - scripts for setting Informix environment variables .............................................................11 Figure 13 - apachectl shell script environment variables section..........................................................12 Figure 14 - contents of the /opt/lampp/bin/envvars file......................................................................13 Figure 15 - LD_LIBRARY_PATH after restart........................................................................................13 Figure 16 - output of phpize command ..............................................................................................14 Figure 17 - end of configure command output....................................................................................15 Figure 18 - make command output (last page)....................................................................................15 Figure 19 - pdo_informix.so shared library.........................................................................................16 Figure 20 - PHP extension_dirlocation...............................................................................................16 Figure 21 - current php.ini file location...............................................................................................17 Figure 22 – adding extensions to the php.ini file.................................................................................18 Figure 23 - pdo_informix installed, loaded, andenabled .....................................................................19 Figure 24 - finding the Informix database server port number.............................................................21 Figure 25 - successful outputfrom test_ifx.php..................................................................................22

×