Connect PHP to AS400 with ODBC or DB2 - php

I'm trying to connect my WEB server to AS400. The web server has not DB2 library neither ODBC library.
I have installed XAMPP in my Windows computer, and one of my colleagues also did.
He has Client Access on his Computer.
We both installed:
- XAMPP
- ibm_data_server_driver_package_win32_v10.5.exe
We tried to install PECL DB2 extension (LINK) but unsuccessfully (got error ".\php.exe appears to have a suffix .exe, but config variable php": seems that nobody has solved this problem on Windows...).
Then we saw that XAMPP has the ODBC Module already on it, so we tried to estabilish a connection with obdc_connect. Referring to THIS question we are now able to connect to AS400 using his computer with Client Access Drivers using:
$user = 'USER';
$password = 'PASS';
$hostname = '192.168.1.30';
$server="Driver={Client Access ODBC Driver (32-bit)};
System=$hostname;
Uid=$user;
Pwd=$password;";
odbc_connect($server, $user, $password);
With my computer I tried to use the IBM data server driver already installed using:
$user = 'USER';
$password = 'PASS';
$hostname = '192.168.1.30';
$server="Driver={IBM DB2 ODBC DRIVER};
System=$hostname;
Uid=$user;
Pwd=$password;";
odbc_connect($server, $user, $password);
and I get always this error:
Warning: odbc_connect(): in C:\xampp\htdocs\test.php on line 11
When I've tried with IBM DB2 ODBC DRIVER on my colleague's computer, I've also got the same error.
What is this error? No information is specified.
We would like to use db2_connect instead of odbc_connect. What should we do to install this extension? I asked my ISP to install the db2 extension on the WEB server but I'm still waiting... maybe he also encountered some problems (the WEB server is a UNIX machine).
Any help is much apprecciated!

Related

How to solve ORA-12154: TNS error when using PHP OCI8 oci_connect in Azure

I'm trying to connect to the oracle database of a new partner, 11g Release 11.2.0.4.0, and I'm receiving the following error:
Warning: oci_connect(): ORA-12545: Connect failed because target host or object does not exist
The partner affirms that the connection string provided is correct.
This is the current structure of mine oci_connect() and the said connection string being used:
$connection_string = '(DESCRIPTION = (ADDRESS_LIST = (LOAD_BALANCE = ON)(FAILOVER = ON)(ADDRESS = (PROTOCOL = TCP)(HOST = HOST)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = SERVICE_NAME)))'
$conn = oci_connect($username, $password, $connection_string, 'UTF8', OCI_DEFAULT);
But, when using the following structure:
$connection_string = 'user/password#host:port/service_name'
$conn = oci_connect($username, $password, $connection_string, 'UTF8', OCI_DEFAULT);
It returns:
Warning: oci_connect(): ORA-12154: TNS:could not resolve the connect identifier specified
To give a clear picture of what I did, below are the steps I took to create my App-Service and install the oci8 php driver:
I created an Azure App-Service, that uses PHP, Version 7.3.26;
Created a new oracle directory inside /home/site;
Added the instant client to the new oracle directory, in this case it was the Instant Client Linux x86-64 18.5.0.0.0v (bouth the basic and the sdk packages);
Proceded to use the command pecl install oci8-2.2.0;
I pointed out the location of the instant client during the installation process, the oci8 driver was installed successfully;
Copied the new oci8.so file to an ext directory inside /home/site;
Created a php.ini file, with extension=/home/site/ext/oci8.so set in;
Defined the PHP_INI_SCAN_DIR config as being /usr/local/etc/php/conf.d:/home/site/ini;
Defined the LD_LIBRARY_PATH as being /home/site/oracle/instantclient_18_5.
After that I could confirm the existence of the oci8 extension on my phpinfo() page.
Those steps where made following this documentation: Azure App Service Linux - Adding PHP Extensions
I also have latter defined the ORACLE_HOME setting as being /home/site/oracle/instantclient_18_5, but it had no diferences.
I'm out of ideas, can someone please indicate me what could be causing this problem and how can I solve it.
EDIT:
After further conversations with the partner it becamed clear that there isn't no way for me to connect to their database considering the current configuration of the same. As noted int the comments by Christopher Jones, its a problem of networking, ORA-12545, ORA-12541, ORA-12514, & ORA-01017 – How to fix for SQL Developer, and, in this case, lack of proper feedback.

How to connect sql server with php using xampp?

I am trying to connect my SQL server with PHP using Xampp. I have already uploaded dll files in the ext folder but I am unable to connect it.
My PHP version is 7.2.6.
Uploaded dll files are - php_pdo_sqlsrv_72_ts.dll, php_sqlsrv_72_ts.dll.
I have written this code to connect my SQL database with PHP-
<?php
$serverName = "INDO-SERV\SQLEXPRESS,1443";
$uid = "sa";
$pwd = "XXXXXX";
$databaseName = "web";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>$databaseName);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_close( $conn);
?>
I am getting this error when I had tried this-
Fatal error: Uncaught Error: Call to undefined function
sqlsrv_connect() in C:\xampp\htdocs\biometric\db.php:7 Stack trace: #0
{main} thrown in C:\xampp\htdocs\biometric\db.php on line 7.
Anyone has an idea where I am doing wrong or how to connect with the database.
Installation of PHP Driver for SQL Server (sqlsrv and/or pdo_sqlsrv PHP extensions) can be done following the next steps:
Based on Microsoft PHP Drivers for SQL Server Support Matrix download appropriate version of this driver. In your case - version 5.2 or 5.3 (32-bit or 64-bit also depends on PHP version).
Download and install an appropriate ODBC driver - see System Requirements for the Microsoft Drivers for PHP for SQL Server
Load PHP Driver for SQL Server as PHP extension.
Restart Apache
Check the configuration with <?php phpinfo();?>. There should be a section with name pdo_sqlsrv (if you use PDO) and/or sqlsrv (without PDO).
my XAMPP version is 7.0.13
1- Download and Install "SQLSRV40.EXE" on this path:
D:\xampp\php\ext
2- Download and Install "msodbcsql.msi"
3- Edit file ":\xampp\php\php.ini" and add this extensions :
extension=php_sqlsrv_7_ts_x86.dll
extension=php_pdo_sqlsrv_7_ts_x86.dll
extension=php7ts.dll
4- restart xampp
Note: "SQLSRV40.EXE" Contain this extensions:
php_sqlsrv_7_ts_x86.dll , php_pdo_sqlsrv_7_ts_x86.dll , php7ts.dll
Download driver from:
https://download.microsoft.com/download/f/4/d/f4d95d48-74ae-4d72-a602-02145a5f29c8/SQLSRV510.ZIP
Unzip the files
Copy the dll files in C:\xampp\php\ext\
Open with your favourite editor the file php.ini located in C:\xampp\php\
Insert the extensions:
extension=pdo_sqlsrv_74_ts_x64
extension=sqlsrv_74_ts_x64
Restart Apache and PHP
For the new comers;
You can setup driver and integrate it as in this video explains so in a nutshell;
You should find drivers for php - sql server integration depending to your environment (versions) at links and download the driver that suits for your environment.
You should move the driver file (.dll for windows case) to php/ext folder.
You need to change php.ini as entering a new extension (for example extension=php_sqlsrv_7_ts.dll) by giving your exact file name you have moved to php/ext.
Restart your local server and you should see this extension in phpinfo(), if you can see it's there, you can connect to your db with your credentials and it's done.
Credits goes to creator of the video (applause) :)

Doctrine on linux: unable to connect to sql server

I am trying to run a zend + doctrine web application from a Debian 9 host, using php 5.6
I've the need to connect to a sql server that is on different host (it's a windows machine, obviously)
I tested connection using isql command line and I am correctly able to login and to operate in the desired db
The problem is that the webabb do not return me any error but simply fails to login (i am not the developer of this webapp).
Configuration follows:
odbcinst.ini
[FreeTds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount = 1
Trace = Yes
TraceFile = /tmp/odbcinst.log
freetds.ini
host ip is exact, I removed when pasting here
[flower1]
host = xxx.xxx.xxx.xxx
port = 1433
tds version = 7.3
odbc.ini
[test_flower1]
Description=Test for MSSQL Server on flower1
Driver=FreeTds
Database=test_flower1
ServerName=flower1
TDS_Version=7.3
application.ini
;; Database
doctrine.dsn = "odbc:Driver={Sql_server};Server=flower1;Database=test_flower1;Uid=<redacted but correct>;Pwd=<redacted but correct>;"
How can I debug the source of the problem?
I've not previously experience with zend/doctrine
The problem was due to this
doctrine.dsn = "odbc:Driver={Sql_server};Server=flower1;Database=test_flower1;Uid=<redacted but correct>;Pwd=<redacted but correct>;"
I solved simply adding the port !
doctrine.dsn = "odbc:Driver={Sql_server};Server=flower1;Port=1433;Database=test_flower1;Uid=<redacted but correct>;Pwd=<redacted but correct>;"

MSSQL VIA FreeTDS, ODBC, and Cpanel Unknown host machine name (severity 2)

I have installed FreeTDS 0.91, ODBC, on a Cpanel server running Centos 6.5x64. Everything appears to be running fine and I can connect to the remote MSSQL 2012 server using:
/usr/local/freetds/bin/tsql -S sqlserver -U test -P mypassword
and succesfully execute queries in the database.
I can also connect through:
isql -v sqlserverdatasource test mypasswordhere
But for some reason /usr/local/freetds/bin/tsql -LH server.ip.here
returns no information or errors which doesn't make much sense when it is proven I can connect with the other methods above.
So now when running a test script from a cpanel account on the machine I get:
Unknown host machine name (severity 2)
Here is the test script:
//Database connection function.
function getConnection() {
try {
//$dbconnect = new PDO("sqlserver:Server=server.ip.here,1433;Database=dbname", "user", "password");
$dbconnect = new PDO("dblib:host=server.ip.here,1433;dbname=dbname", 'user', 'password');
} catch (PDOException $e) {
echo "CONNECTION ERROR.<br>Error message:<br><br>" . $e->getMessage();
die();
}
if (!$dbconnect) {
die('Cant connect to database. Please try again later!');
}
else{
echo "i'm in!";
return $dbconnect;
}
}
The first commented line is the old one using sqlserv which I found did not work at all from what i can tell because of the x64 OS. I have also tried with "" around user and pass as well as no marks at all.
php -m does show PDO and pdo-dblib.
Any ideas where I can look next?
Update: This was fixed. I missed in freetds.conf:
[global]
# TDS protocol version
tds version = 8.0
It was originally set to 4.5 instead of 8.
The fix for me was with three steps:
First, I edited /etc/freetds/freetds.conf and changed the tds version like this:
tds version = 8.0
The second step was not entering port number. The port was already 1433, and not specifying it fixed the exact same issue on my case.
Lastly, to connect properly, I had to restart networking as #user1054844 mentioned as this:
/etc/init.d/networking restart
After all these steps, I was able to connect and work with the SQL Server database.
You actually did not need ODBC at all since your connect script is using pdo_dblib not odbc. You can just install FreeTDS than enable pdo_dblib via the compile time flag in rawopts and rebuild via EasyApache. Of course cPanel specifics for this are a bit different.
I just did this for a friend and decided to document it since it is hard to find accurate clear information for FreeTds and pdo_dblib on cPanel.
Guide is here: FreeTDS And pDO_dblib On cPanel

php5 odbc_connect() function error when connecting to Visual FoxPro9 table

I'm running php5 on Ubuntu10.10 server where the unixODBC and php5-odbc packages have already been installed. I keep getting an error during the connection process - code:
$data_source = 'DRIVER={Microsoft dBASE Driver (*.dbf)};Data Source=//128.251.xxx.xxx/lv_apps/AppsLON/CData/dbf/cdma';"", "");
$conn = odbc_connect($data_source, "", "");
if (!$conn)
exit("Connection Failed: " .$conn );
error message:
1 Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /var/www/vfptest.php on line 6
I added extention=dbase.so and extention=odbc.so to both files: /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini and re-compiled the php install with:
sudo ./configure --prefix=/usr --enable-dbase=shared --with-unixODBC
I've also gone to unixODBC and pecl to install the unixODBC and dbase libraries separately with no luck.
Also I found this link: http://www.devlist.com/ConnectionStringsPage.aspx
where it is stated that in order to create an ODBC connection to a foxpro database I use the line:
Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=c:\demo.dbc;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO
this still did not work for me however; probably because I do not have the visual foxpro driver installed or my odbc.ini file pointing to the driver path...but I don't know.
In short - odbc_connect() takes; an ODBC Data Source Name (DSN), Username & Password as per --
http://php.net/manual/en/function.odbc-connect.php
As far as I am aware there is no VFP ODBC driver for Linux so you will, most likely, need to employ an ODBC Bridge solution like -
http://uda.openlinksw.com/odbc-odbc-mt/
This has a client/server architecture --
Linux client --
php ODBC Application
OpenLink Generic ODBC Driver (thin multi-tier ODBC client)
Windows server --
OpenLink Request Broker (Multi-tier server)
OpenLInk Agent for ODBC (Multi-tier server)
Fox Pro ODBC DSN (pre configured)
Fox Pro files...
I hope this helps?
Check out the very bottom of this thread on the MSDN network
the driver line you have posted is "...an ODBC connection string which is not supported for VFP tables having a version later than 6."
Although not familiar with linux connecting to VFP, however, odbc connections for such VFP connect to a PATH, not a specific table. Once the connection to the PATH is valid, THEN you can query any .DBF table IN that location.
Although I can't answer your specific connection info, I've found this link
http://www.phpfreaks.com/forums/index.php?topic=296832.0
that shows connecting to a datasource... notice its identifying the 'DRIVER={Microsoft dBASE Driver (*.dbf)};datasource=/home/dir/file.dbf;' used... You'll probably have to hit a combination of this driver and pathing info (I'd still try WITHOUT the specific .dbf file first).
Hope this helps..

Categories