I'm trying to connect to remote DB2 via PHP. But have some problems. I've already installed IBM Application developer client.
phpinfo() output:
IBM DB2, Cloudscape and Apache Derby support enabled
Module release 1.9.4
Module revision $Revision: 327944 $
Binary data mode (ibm_db2.binmode) DB2_BINARY
Then, I've got a php file which is looking like:
$database = 'MyDB';
$user = 'db2inst1';
$password = 'mypassword';
$hostname = '1.1.1.1';
$port = 50000;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;PORT=$port;HOSTNAME=$hostname;".
"PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');
if ($conn) {
echo "connection to $database succeeded";
} else {
echo "connection to $database failed";
echo db2_conn_errormsg();
}
And trying to execute this file, I have "connection to MyDB failed", and NO visible response from db2_conn_errormsg(), which is actually making me baffled
Unfortunately, I haven't got a straight access to the remote server with database. But several months ago, when I was using other client, I succeeded to connect to exactly this database. But that time I didn't need to install IBM ADCL. That is why I can guess that problem is on this side. But even if so, I couldn't fix it.
Sorry if I duplicated some question on stackoverflow, but all answers, which I found, were unfortunately useless to me.
I'm using Apache 2.2 and PHP 5.4.
Hope you can help.
Thanks for any replies!
Are you sure you have connectivity to the server? Correct port, server, firewall rules, username, password, database name?
What is the SQL code you are receiving. Try to get the SQL code from PHP, "connection to xx failed" is your own code so it is useless to help you.
Did you install the application development client? which DB2 version are you using? ADCL is old, it was for DB2 8. Since DB2 9.7, clients have different names, and I think you need IBM Data server client in order to compile the php module. For more information, check this website: http://www-01.ibm.com/support/docview.wss?uid=swg27016878
I think you have to catalog the database server (node) and the database in the local machine with the db2 client. It seems that your PHP code uses ODBC driver, and it has to be configured locally.
Your connection string looks like an ODBC connection where as the db2_connect function in PHP needs :-
DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;
It's on the PHP web page.
I have never been able to get ibm_db2 or pdo_ibm working on a remote. They work if DB2 and Apache are on the same machine (like the iSeries) but not if the host is connecting to a remote DB2.
If you read the Doctrine2 PHP drivers for each you will find they redirect to ODBC if the host is not 'localhost' or '127.0.0.1'.
This code works for me
<?php
if (!$db = odbc_connect ( "AS400", $user, $password) )
echo 'error!';
$result = odbc_exec($db, "select count(*) from $table");
while (odbc_fetch_row($result)) {
var_dump($result);
print_r($result);
echo "\n";
echo odbc_result($result, 1)."\n";
}
odbc_close($db);
AS400 is DSN name defined in ODBC.
Related
I'm trying to connect to a MSSQL database with odbc in php.
My issue is similar to this issue, I can connect with tsql, but not with php.
The answer to the problem not work because I think I don't have SELinux installed (I don't know what it is, but pacman not found this package (or with a similar name) on my computer)
I don't understand why it doesn't work, odbc is installed and detected by php
print_r(PDO::getAvailableDrivers());
Array ( [0] => odbc )
I'm connecting by doing that:
$dsn = 'odbc:Driver=FreeTDS;Server=127.0.0.1;Port:1433;Database=[my base name]';
$pdo = new PDO($dsn, $user, $password);
My base is not in local, I use a ssh tunel because the base in accessible only at my school, and we need an ssh tunnel. And it work, I can connect myself to the base with tsql.
When I was connecting PHP to our MS SQL server, I could never get a connection established using ODBC drivers.
Instead, I downloaded the official PHP > SQL SERVER drivers direct from Microsoft. You can find them here.
Once installed, you must configure your php.ini file to include the new drivers, restart your web server and then use the following to open a new connection:
$conn = new PDO("sqlsrv:Server=SERVER_IP,1433;Database=DATABASE_TO_OPEN;");
I'm trying to configure an SMS GATEWAY USING OZEKING but I'm getting an error which has something to do with MYSQL ODBC DRIVER not being found. I have the driver installed on my Windows 10 machine and I'm not sure if I'm doing the right thing. In the OZEKING configuration I'm seeing this in the picture below:
The error I'm getting is :
12/16/2015 14:51:47 - INFO 6021: Connecting to database ODBC, DRIVER={MySQL ODBC 5.3 Driver};Server=localhost;Database=dbtest;UID=root;PWD=password#87;.
12/16/2015 14:51:47 - ERROR 6001: Database connection error: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified. ODBC;DRIVER={MySQL ODBC 5.3 Driver};Server=localhost;Database=dbtest;UID=root;PWD=password#87;
12/16/2015 14:51:47 - INFO 6026: Will try to reconnect to database in 20 seconds.
My question is what exactly am I doing wrong?
These parameters I'm entering Server=localhost;Database=dbtest;UID=root;PWD=password#87 are the ones I'm using to connect to my database, i.e:
$serverName = "localhost";
$userName = "root";
$password = "password#87";
$databaseName = "dbtest";
//create connection and select database by given data
$GLOBALS["connection"] = mysql_connect($serverName, $userName, $password);
if ($GLOBALS["connection"] == null)
{
echo mysql_error() . "<br>";
return false;
}
Anyone to assist me the correct way of doing things. Thanks.
ODBC drivers installed are 32-bit OR 64-bit, make sure you installed the correct architecture for your machine.
(install both to be safe)
Click Start and type "ODBC", you'll be given an option for your 32-bit and 64-bit sources, check them both and make sure your 5.3 driver is installed under both.
I have a Linux server running Wordpress 4.2 and I have 2 Azure DB, one is SQL Server and the other is CleanDB.
The Windows Server(s)
Windows 7 Pro/Windows Server 2012 R2 sp1
Visual Studio 2013
SQL Server 2012 sp1
PHP 5.4 WP 4.2
Linux Server
CentOS 6.0
WP 4.2
PHP 5.4.31
It runs on SQL server, visual studio, and my php script on my Windows server to the CleanDB and SQL Server run fine and when I run the connection string on the Linux server to the CleanDB.
It won't connect when I run the Linux server to the SQL server.
I only allowed the DB to allow 4 calls and it isn't pulling.
The IP ranges were added on the firewall.
I used the exact same string in all instances.
I found a few other related questions that some help:
SO References:
Cannot connect to azure db via SqlConnection
"Call to undefined function sqlsrv_connect()" when trying to connect to Azure DB from PHP
MSDN References:
https://azure.microsoft.com/en-us/documentation/articles/sql-database-php-how-to-use/
https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-connect-on-premises-sql-server/
it won't connect when I run the Linux server to the SQL server.
Do you mean you couldn’t connect to SQL Azure from a Linux server while using sqlsrv drive? Please note, SqlSrv is a Windows driver, on Linux we can use PDO_DBLIB drive and PDO_ODBC (not recommend), more detailed info could be found at: http://php.net/manual/en/ref.pdo-dblib.php.
Code snippet via using PDO_DBLIB for your reference:
<?php
$dbHost = 'YourName.database.windows.net';
$dbUser = 'DBUserName';
$dbPass = 'DB Password';
$dbName = 'DB Name';
try {
$pdo = new PDO("dblib:host=$dbHost:1433;dbname=$dbName", $dbUser, $dbPass);
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
Code snippet via using PDO_ODBC for your reference:
$connection = odbc_connect("Driver={SQL Server};Server=$dbHost; Database=$dbName;", $dbUser, $dbPass);
$qry = "SELECT * FROM Clienti";
$result = odbc_exec($connection,$qry);
// Get Data From Result
while ($data[] = odbc_fetch_array($result));
// Free Result
odbc_free_result($result);
// Close Connection
odbc_close($conn);
// Show data
print_r($data);
AS to DB settings, please do not forget to manage allowed IP addresses on Azure portal, i.e. add your client IP address in Allowed IP Addresses section on Azure portal. https://msdn.microsoft.com/en-us/library/azure/ee621782.aspx#Troubleshooting
Feel free to let me know if I have any misunderstood on your issue.
I am install service MySQL to my PHP app on Bluemix and the error is on connection establish on this lines:
$con = mysql_connect("192.155.247.248:3307","uqDqUZ2EKoZ5I","pWXeBZbNtdpOv");
if (!$con){
echo "Failed to connect to MySQL: " .mysql_error();
}
mysql_select_db("d65a2b7e14b594d18a049ac918a4a8603",$con);
Quentin suggested to use mysqli instead of mysql_* as the latter is deprecated, i.e. try this:
$mysqli = new mysqli("192.155.247.248:3307","uqDqUZ2EKoZ5I","pWXeBZbNtdpOv", "MYDB");
$result = $mysqli->query("SELECT * from MYTABLE");
$row = $result->fetch_assoc();
Create a folder
.bp-config/options.json in the parent folder
and add
{
"PHP_EXTENSIONS": ["mysqli"]
}
in the options.json folder
the sqli connect will work fine now
Are you getting:
ERROR 2003 (HY000): Can't connect to MySQL server on '$host' (60).
A developer may have asked a similar question on developerWorks.
The answer seemed to be as follows:
Downloaded the latest PHPMyAdmin(4.1.9)
Created a BlueMix application using - cf push -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git
${myPhpAdminApp} . Note: the PHP build pack is used is PHP 5.4.26, which enables multi-byte support (it is different from the Heroku one in the BlueMix docs). This was necessary because the Heroku pack bundled PHP 5.3.27 which
doesn't enable "multi-byte" character support by default. Multi-byte
support is required to be enabled by PHPMyAdmin apparently.
Added the existing MySQL service to this app. And picked the host, port, user, and password details from the VCAP_SERVICES
environment variable.
Copied config.sample.inc.php in the PHPMyAdmin to config.inc.php and added or modified the following lines in it based on the MySQL
service VCAP_SERVICES details picked in previous step -
$cfg['Servers'][$i]['host'] = 'host-ip-from-vcap_services';
$cfg['Servers'][$i]['port'] = 'port-from-vcap_services';
$cfg['Servers'][$i]['user'] = 'user-from-vcap_services';
$cfg['Servers'][$i]['password'] = 'password-from-vcap_services';
Pushed the updates using the above cf push ... again.
I'm trying to connect to my local SQL Server 2008 R2 (have also tried it with 2005, same result exactly) with PHP. I'm using PHP 5.1 which still supports php_mssql and mssql_connect().
for some reason PHP just won't find my server, I can connect via ODBC flawlessly an that's fine, but I would like to connect to SQL Server directly.
I have connected PHP to SQL Server a million times on different servers, this one seems to be the only one giving me issue.
This is my little test code to try and get the connection working.
//define connection garbage
$db['hostname'] = "USER90C6\SQLEXPRESS";
$db['username'] = "user";
$db['password'] = "password";
$db['database'] = "kal_auth";
//connection string
$conn = mssql_connect($db['hostname'], $db['username'], $db['password']);
//does it work? :o
if($conn)
{
echo "works";
}
else
{
echo "fails";
}
The error this code produces:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: USER90C6\SQLEXPRESS in C:\xampp\htdocs\test.php on line 9
fails
Is there something seriously wrong with my setup? or am I missing something.
Did you enable TCP/IP on the server's configuration tool?
Is the firewall blocking any ports you might be using?
Are your MDAC (microsoft data access components) updated?
turn on mssql.secure_connection in php.ini
I think you don't miss anything.. Your connection string seems to be right (you receive a "Unable to connect" error..).
In my opinion, you problem can be a version incompatibility or a user privileges mistake. First of all: look at DLL driver you are using in PHP and check it's compatibility with you MSSQL version.
Maybe can be a good idea a fresh PHP install, with the latest stable release, if it is possible. Give a look at: http://www.php.net/manual/en/mssql.requirements.php
Good luck.