Skip navigation
7801 Views 4 Replies Latest reply: Mar 9, 2012 12:01 PM by Patrick McCann RSS
Scott F New Enzee 1 posts since
Aug 4, 2011
Currently Being Moderated

Aug 4, 2011 7:00 PM

Connecting to Netezza database using PHP & Linux

I have successfully connected to the Netzza database from a Linux box and am able to run queries. I am having issues when i try connecting via ODBC in PHP.

The error I get is:

 

Message:  odbc_connect(): SQL error: [unixODBC]Server and/or port attributes are empty, SQL state S1000 in SQLConnect

 

I believe I am really close in getting a connection however this last bit of error has got me scratching my head.

 

I am trying out the following code:

 

$connect = odbc_connect("NZSQL","username","password");

 

        if($connect){
           echo "smoething";
        } else {
           echo "nothing";  
        }

 

 

 

In the code above, the DSN name is NZSQL.

 

What could be wrong here?

  • Paul Froggatt Active Enzee 220 posts since
    May 20, 2006
    Currently Being Moderated
    1. Aug 5, 2011 8:44 AM (in response to Scott F)
    Re: Connecting to Netezza database using PHP & Linux

    Have you tested ODBC connection to Netezza using the Netezza supplied nzodbcsql test utility ?, I would suggest doing that first before trying to use PHP.  It sounds like a problem in your odbc configuration, if the nzodbcsql utility gives the same error that would confirm it, then you'll need to go back over your configuration, e.g. re-check your odbc.ini odbcinst.ini files, check you've exported the approriate environment variables, etc., as documented in the README file supplied with the ODBC driver.

  • rdinoff New Enzee 40 posts since
    Dec 1, 2009
    Currently Being Moderated
    2. Aug 8, 2011 5:47 PM (in response to Scott F)
    Re: Connecting to Netezza database using PHP & Linux

    In the [NZSQL] section of your .odbc.ini file make sure the server and/or port are correct.  Look at Netezza_odbc_jdbc_guide.pdf on the ftp site or the sample odbc files in /usr/local/nz/lib. 

     

    Also "isql -v NZSQL" needs to work, php uses the unixODBC utilities. If isql works then it means the shared objects and ini files have been configured properly.

  • Saket Kale New Enzee 17 posts since
    Jan 12, 2012
    Currently Being Moderated
    3. Feb 10, 2012 6:36 AM (in response to Scott F)
    Re: Connecting to Netezza database using PHP & Linux

    Did you check the the log file that is generated by odbcinst.ini, there you will be able to see the location from where it is trying to pick up the odbc.ini file.

     

    Also, a sample odbc.ini filw would be:

     

    [ODBC Data Sources]
    NZSQL = NetezzaSQL

     

    [NZSQL]

     

    Driver=/root/Desktop/libnzodbc.so
    Description=NetezzaSQL ODBC
    Servername=nzdev.xxx.xxx
    Port=5480
    Database=dev
    Username=admin
    Password=password
    ReadOnly=false
    ShowSystemTables=false
    LegacySQLTables=false
    LoginTimeout=0
    QueryTimeout=0
    DateFormat=1
    NumericAsChar=false
    SQLBitOneZero=false
    StripCRLF=false
    securityLevel=preferredUnSecured
    caCertFile=

     

    This is a demo version of the file.

     

    Also, you need to set the environmental variables when you login or in the .bashrc file.

     

    Regards,

     

    Saket Kale.

  • Patrick McCann New Enzee 6 posts since
    Oct 31, 2011
    Currently Being Moderated
    4. Mar 9, 2012 12:01 PM (in response to Scott F)
    Re: Connecting to Netezza database using PHP & Linux

    I ran into this post when I had the same problem when launching my odbc connection from within Rstudio.  The responses above don't seem to notice you are connecting fine outside of PHP from the same box. Here is what finally worked for me: make sure your ODBCINI=/etc/odbc.ini & NZ_ODBC_INI_PATH=/etc environment variables are getting set in the php environment and your ld_library_path is pointing at /usr/local/nz/lib and lib64 in the php environment.

     

    Message was edited by: Patrick McCann

More Like This

  • Retrieving data ...

Bookmarked By (1)