I am following the process as described here:
https://www.ibm.com/support/knowledgecenter/en/SSHRBY/com.ibm.swg.im.dashdb.doc/connecting/connect_connecting_php.html
I have completed the instalation and I have even run the validation command in shell
db2cli validate -dsn DashDB -connect -user bluadmin -passwd 'your_secret_password'
see output below
But still my www page crashes on the line
$conn = odbc_connect( $conn_string, "", "" );
becasue it does not recognize the odbc_connect function.
Any feedback and hopefully help is very welcome.
Your question is not about programming, but instead it is about configuration.
It is best if you detail your php version and your linux distro details fully every time you ask for help.
You already successfully configured db2dsdriver.cfg and successfully validated a CLI connection to the remote Db2 database. That is essential.
The next step is to ensure that both ODBC and PHP are configured appropriately.
It may help to verify all the following items:
Verify php-odbc is installed to match your version of php . Use the package-manager (e.g. yum or apt etc.) for your linux distro to install it, there's plenty of pages to help you with that.
Verify the php.ini has enabled: extension=odbc.so ( for Linux it seems this is not default with php7).
Verify that the command-line php -m shows that odbc is loaded
If you configured a unixODBC DSN then verify you can successfully connect to the DSN with isql command on linux (to verify that your odbc.ini and odbcinst.ini are properly configured with the Db2 driver and the DSN details). Use odbcinst -j to show the path to odbc.ini and odbcinst.ini for your distro. There's plenty of pages to show how to configure those files, and how to run the isql command line. Usage of a DSN is optional, but it can help with sanity checking and centralises the connection strings instead of having them replicated in php scripts.
verify the ibm_db2 driver is loaded and pdo_ibm (if using PDO interfaces) with the php -m command line.
Related
I'm buildig a simple web application in Laravel 8 using PHP 7.4 and Azure web services. The app runs perfectly on my local machine, but once I try to push my app to Azure I'm getting a PHP 500 error for all pages where some sort of querying is needed.
It turns out that I'm missing a pdo_mysql driver that hasn't been enabled when setting up our Linux server. I've been looking through all the Azure documentation and I can't seem to find how to turn this pdo extension on.
Strange thing is Azure provides us two terminals: the SSH terminal and a Bash terminal (Kudo remote execution terminal). When I run
php -m
in the SSH, the pdo_mysql module does show up in the list. I can also migrate my tables within the SSH. But once I run the same
php -m
command in the Bash terminal, the module is not showing. Migrating tables in that terminal is also not possible, because it says I'm missing the pdo_mysql driver. The Oryxbuilder that builds my application after each git deployment also notices that I'm missing the pdo_mysql driver and returns the same error.
So how can I enable this module in Azure? Can anyone please help me?
First of all i'd check to see if its enabled in the php.ini file, often located at /etc/php/{version}/cli/php.ini , cli may also be cgi or apache2.
We are attempting to use PHP to interface with Progress databases to insert, retrieve, update and delete character strings in a variety of languages using PHP.
Here's what does work:
We can connect using unixODBC and isql and run an update script to update a field with unicode characters and it works fine.
Run a php script from a command line that will run an update script to update a field with unicode characters that that works fine too.
If we have a webserver call the exact same PHP script from 2) above, it updates the record in the table with values that would be an extra encoding of the unicode.
There was a known issue with unixODBC that used to do double encoding of unicode values and the version of the platform we're working on originally had an older version of the driver that had the problem. We installed newer unixODBC drivers that do not have the problem (2.3.9 I believe) and now the isql and command line PHP work properly as a result.
What we suspect is that the the web server is still using the older version of unixODBC even though we've attempted to ensure it uses the environment variables we've set for LD_LIBRARY_PATH, ODBCINI and ODBCINST by adding those definitions as part of the httpd for Apache.
I had hoped that the solution listed as Edit3Solution on this question Cannot Connect to informix through ODBC on linux machine would be what resolved things for me, but we already had taken the step of adding our environment variables to httpd but no dice.
In the phpinfo from a browser, we see:
Apache Environment
Variable Value
LD_LIBRARY_PATH /usr/lib:/dr01/repository/lib:/qad/progress/dlc11264/lib
ODBCINST /etc/odbcinst.ini
ODBCINI /etc/odbc.ini
But we also see:
ODBC
Support enabled
Active Persistent Links 0
Active Links 0
ODBC library unixODBC
ODBC_INCLUDE -I/usr/include
ODBC_LFLAGS -L/usr/lib64
ODBC_LIBS -lodbc
To try to get around this, we attempted to set virtual paths to the odbc relevant code in the /usr/lib64 directory to the /usr/lib directory for just the odbc related files.
So far no luck. The behavior is the same.
Is it possible that the Apache server has it's own unixODBC that it uses when it calls PHP and ignores the unixODBC we've defined on the server?
I've been searching and trying for quite a while to find an answer, so will finally ask here.
I have a UBUNTU install from Turnkey LINUX, PHP Ver 5.6.23.
I have compiled and enabled mssql.so as I require to connect to a MSSQL server.
My simple connect PHP script is so:
$server = 'rslocal';
$connect = mssql_connect($server, 'sqluser', 'sqlpassword');
if (!$connect) {
echo 'can not connect';
}
I can run the above PHP script from the command line and it is successful.
I can also run the FreeTDS tsql utility and connect and query the server from the command line
When I run it from the browser through Apache, it tells me
Fatal error: Call to undefined function mssql_connect() ...
I have checked that php --ini (cli) and phpinfo() (browser) both report the same ini file in use.
I am not running SELinux so the setbool commands are not relevant here, however the problems stated by others where SELinux WAS the issue are exactly the same as mine, so perhaps this is a place to start.
My feeling is that it is a security policy or something stopping the extension from loading any function that wants to communicate with an outside server, but I am stuck.
Any help would be appreciated.
I found the "answer". On this distro, Ubuntu 14.x, the command
sudo apachectl restart
doesn't seem to be enough to reload php. The php.ini change, specifically adding extension=mssql.so had not been not applied when run through apache. This raises the question how to "hard" restart Apache so php.ini changes take, but that's a different question. I only noticed that it worked after a reboot.
I have installed FreeTDS on my Mac, but I'm having some issues connecting using mssql_connect.
First, when I run tsql -C I see that the freetds.conf directory is listed as /opt/local/etc/freetds. I have a freetds.conf file inside this directory.
Next, if I connect like this:
$connect = mssql_connect('IP_ADDRESS', 'username', 'password');
then everything works as expected. That is, I can retrieve, update, insert data from/into whichever DB I select with mssql_select_db().
If I try to connect like this:
$connect = mssql_connect('DSN_NAME', 'username', 'password');
where DSN_NAME matches a datasource specified in my freetds.conf file then I get an error and unable to connect to server: DSN_NAME which tells me that PHP isn't correctly seeing the path to my freetds.conf file.
However, if before my call I add:
putenv("FREETDSCONF=/opt/local/etc/freetds/freetds.conf");
then everything works as expected. This tells me that my freetds.conf file is formatted correctly.
I've searched all over about how to find the path that PHP thinks the freetds.conf file is in, but I can't find that.
Lastly, there are some reasons I don't want to use the IP address directly in my connection as well as why I don't want to be forced to use the putenv() method to specify the directory.
Any ideas?
Thank you.
When I installed FreeTDS I originally used MacPorts. I believe that this gave me some conflicts for where freetds.conf should have been. And even though the path for freetds.conf when running tsql -C was the actual path that I was attempting to use, when I compiled the mssql.so extension with that path PHP wouldn't recognize it.
The solution is to forget MacPorts for FreeTDS and just install FreeTDS from source. Then install the mssql.so extension from the PHP source and make sure you're using the same version that is on your system (mine was 5.3.13 under OS X Mountain Lion).
If you follow the instructions at this blog exactly you shouldn't have any issues.
A couple of final things:
I am NOT running MAMP even though the instructions mention it so it won't matter either way.
If you already did install FreeTDS via MacPorts, uninstall using: sudo port uninstall freetds +odbc and then sudo port uninstall unixODBC. Make sure you uninstall all instances of FreeTDS. If you have more than one, you'll get a notice when you run uninstall that you need to specify the version to uninstall.
How do you connect to Oracle using PHP on MAC OS X?
I would think OCI would be the way to go. PHP has a module for it.
The PDO abstraction layer can be used to connect to, and perform actions on, an Oracle DB. Here's an article on how to use PDO with Oracle from the Oracle website.
It's also possible to use OCI.
The Oracle PHP Development Centre will have lots more useful information on using Oracle and PHP together.
For instantclient on osx 10.6 64bit do the following:
download the instant client librarys and sdk, stuff it all in a folder. Make sure you get the 64 bit library if you are on a 64 bit machine, 32bit won't work!
- test with sqlplus first
create this if it does not exist
sudo vi /etc/launchd.conf
and add to following to the file(with your own path!)
setenv DYLD_LIBRARY_PATH /usr/oracle_instantClient64
You probaby need to restart your system at this point for launchd to pass the path to apache to pick up the path, or see if restarting launchd works, though i have a feeling that will restart your system anyway!
You should add "extension=oci8.so" to php.ini
sudo vi /etc/php.ini
if that file does not exist copy php.ini.default
sudo cp /etc/php.ini.default /etc/php.ini
then add the above extension, there is a section with lots of extensions further down the file, put it there somewhere
oci requires a library symlink so do
sudo ln -s $DYLD_LIBRARY_PATH/libclntsh.dylib.10.1 $DYLD_LIBRARY_PATH/libclntsh.dylib
Also theres some wierd hardcoded library link in the oracle binaries so fix that
mkdir -p /b/227/rdbms/
Its only looking for the oracle libraries so link it back
ln -s /usr/oracle_instantClient64/ /b/227/rdbms/lib
now install oci8 from pear repository. If you have installed snow leopard osx 10.6 without upgrading you may have problems with pear and pecl. If so you will need to install pear first. see: https://discussions.apple.com/thread/2602597?start=0&tstart=0
sudo pecl install oci8
HINT: don't use autodetect, specify the instantclient path when it asks you..
instantclient,/usr/oracle_instantClient64
restart apache
sudo apachectl graceful
test by navigating to the URL in a browser or you can call the file directly on the command line
php index.php
thats it
use the following as a test file..
<?php
$dbHost = "localhostOrDatabaseURL";
$dbHostPort="1521";
$dbServiceName = "servicename";
$usr = "username";
$pswd = "password";
$dbConnStr = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=".$dbHost.")(PORT=".$dbHostPort."))
(CONNECT_DATA=(SERVICE_NAME=".$dbServiceName.")))";
if(!$dbConn = oci_connect($usr,$pswd,$dbConnStr)){
$err = oci_error();
trigger_error('Could not establish a connection: ' . $err['message'], E_USER_ERROR);
};
$strSQL = "SELECT SYSDATE FROM DUAL";
$stmt = oci_parse($dbConn,$strSQL);
if ( ! oci_execute($stmt) ){
$err = oci_error($stmt);
trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
};
while(oci_fetch($stmt)){
$rslt = oci_result($stmt, 1); print "<h3>query returned: ".$rslt."</h3>";
}
?>
I dont know the Mac specifically, nor PHP, but you usually need to install the Oracle Client tools (Instant Client).
http://www.oracle.com/technology/tech/oci/instantclient/index.html
Once installed you modify the TNSNAMES.ORA file to point to the server and instance name of the Oracle database.
Then you can use the PHP "database connection" stuff (sorry) to create a connection and running your SQL statements.
Use the SQL*PLUS client to check the connection works:
ie.
c:> SQLPLUS
CONNECT scott/tiger#mydatabase
If the TNSNAMES.ORA is correct you should get a connection, or at least "username/password incorrect" that proves you got communication with the Oracle instance.
If you get TNS-12521 (?) errors then your TNSNAMES.ORA is incorrect.
Connecting to an oracle database should be no problem with the oci-interface, using "oci_connect()" for example.
Further examples are here:
http://php.net/manual/en/oci8.setup.php
But I do not understand, what the remark MAC OS X means - are you running an apache locally?
Hope this helps,
Bastian