Aug 4, 2011 7:00 PM
Connecting to Netezza database using PHP & Linux
-
Like (0)
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?
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.
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.
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.
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

