Connecting to a Remote SQL Server 2008 PHP - php

I'm facing this error while trying to connect to a remote SQL Server 2008.
SQLSTATE[08001]: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53].
I use the following code to connect to the database.
$dsn = 'sqlsrv:server=SERVER_NAME:1433 ; database=testDB';
$user = 'user';
$password = 'password';
$dbConn = new PDO($dsn,$user,$password);
When I try to connect using sqlcmd from a command prompt I'm able to connect to the database. I tried connecting using the command :
SQLCMD -U user -P password -S SERVER_NAME,1433
What might be causing this issue? I also do not have SQL Configuration manager installed in the server. How can I fix/debug this issue?

Related

Connect PHP to AS400 with ODBC or DB2

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!

PHP Adaptive Server connection failed (severity 9)

I'm trying to connect to microsoft SQL server 2008 my application is running on a linux server and I have the dblib pdo driver installed. I used port forwarding to connect thru port 1433. I keep getting this message:
SQLSTATE[01002] Adaptive Server connection failed (severity 9);
PHP:
$connect = new PDO('dblib:host=ipaddres:1433;dbname=namedb','username','password');
I suggest to test DB connectivity w/ tsql in this way :
tsql -H server_address -p 1433 -U user -P pass -D dbname
in my case I found that simply "Reason: The password of the account has expired"
PDO gave me a strange error while tsql gave me the right error.
I got the same problem when rewriting a script from mssql_ functions to pdo.
I noticed that the old code did not have a mssql_select_db, but i used dbname in pdo.
When i removed the dbname parameter the connect worked.

Unable to connect to PostgreSQL server

I'm trying to connect to the PostgreSQL database of my app on Heroku:
$host = "ec2-54-235-242-31.compute-1.amazonaws.com";
$username = "user";
$password = "pass";
$database = "dbname";
$port = "5432";
$dbconn = pg_connect("host=".$host." port=".$port
." dbname=".$database." user=".$username." password=".$password)
or die('Could not connect: ' . pg_last_error());
but I'm getting this error:
Warning: pg_connect() [function.pg-connect]: Unable to connect to PostgreSQL server: FATAL: no pg_hba.conf entry for host "69.196.177.196", user "user", database "dbname", SSL off in D:\wamp\www\heroku_app\test.php on line 53
What is the problem here? How can I fix it?
Note: this only happens when I run on my local machine (via WAMP server). If I deploy it to Heroku then it runs fine
The key error here is SSL off. Heroku Postgres requires SSL for external connections. Make sure your PHP was compiled with SSL and specify it in your connection sslmode=require.
Heroku Postgres: External connections (ingress)
Check this quick tip for further help, but, briefly, you obtain your credentials using:
heroku pg:credentials COLOR
... where COLOR is part of the return value from:
heroku addons:add heroku-postgresql
which doubles as the command to add postgres to your application.
Add "sslmode=require;" to your connection string.

ODBC connection failed to DB2 instance with PHP 5.3.6-13ubuntu3.6

I have installed DB2 Express-C V9.7, unixODBC php5-odbc and iSerie-5.4.0-1.6 Drivers for Linux but when i try to connect to the DB2 server php return me this message :
[unixODBC][IBM][iSeries Access ODBC Driver]Communication link failure. comm rc=10061 -
CWBCO1049 - The iSeries server application is not started, SQL state 08004 in SQLConnect
I noticed with tcpdump that php try to connect on port 8741 instead of 50000.
netstat -anp tell me DB2 listen port 50000
This is my configuration file
/etc/odbcinst.ini :
[DB2]
Description = ODBC for DB2
Driver = /opt/ibm/iSeriesAccess/lib/libcwbodbc.so
Setup = /opt/ibm/iSeriesAccess/lib/libcwbodbcs.so
FileUsage = 1
Threading = 2
DontDLClose = 1
UsageCount = 1
/etc/odbc.ini
[local_db2]
Driver = DB2
System = localhost
User = db2inst1
Password = MySecretPassword
Port = 50000
Database = dbname
Option = 1
And my PHP Script :
$dsn = "local_db2";
$user = "db2inst1";
$passwd = "MySecretPassword";
$conn = odbc_connect($dsn,$user,$passwd );
echo "votre id de connexion est : $conn";
if ($conn <= 0) {
echo "\nErreur\n";
}
else { echo "\nSuccès\n";
}
odbc_close($conn);
Now i can connect to DB2 server. I have changed port of db2inst1 in /etc/services but server don't respond me.
My error message is (after a while):
[unixODBC][IBM][System i Access ODBC Driver]Communication link failure. comm rc=8405 - CWBCO1047 - The IBM i server application disconnected the connection, SQL state 08S01 in SQLConnect
Conclusion :
The first problem was the drivers for iSeries that was not the proper drivers for my configuration so i have installed the DB2 ODBC CLI driver which include drivers for linux.
The second problem was the odbc configuration.
My working /etc/odbc.ini configuration :
[DBNAME]
Driver=DB2
My working /etc/odbcinst.ini configuration :
[ODBC]
Trace = yes
Tracefile = /tmp/odbc.log
[DB2]
Description = DB2 Driver
Driver = /opt/ibm/db2/V9.7/lib32/libdb2.so
FileUsage = 1
DontDLClose = 1
You can get more details about your odbc connection in /tmp/odbc.log.
I used too the isql program who test odbc connection.
This program was in unixodbc linux package.
Thanks for your informations
Nicolas.
It's likely the database host server has not been started. The database host server accepts TCP/IP connections to the database.
You can check if it is currently active with the command WRKACTJOB SBSD(QSERVER) JOB(QZDASRVSD).
The command to start it is: STRHOSTSVR SERVER(*DATABASE).
The default port is 8471.

"Can't connect to local MySQL server through socket" on linux server

I'm having a hard time getting my website connected to the mySQL database on host. However, when I was running my website on the PC by Apache it was connecting smoothly. The snippet I'm using to connect is:
<?php
$conn_error = 'Could not connect';
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_db = 'firstdatabase';
if(!mysql_connect($mysql_host,$mysql_user,$mysql_pass)|| !#mysql_select_db($mysql_db)){
die($conn_error);
}else{
//echo 'Connected';
}
?>
And it gives me the following error when I try to connect to mysql on the web host:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server
through socket 'MySQL' (2) in /home/umudo/public_html/connectserver.inc.php on line 10
I searched through the web for finding a solution but couldn't find any exact example of this.
Help: http://dev.mysql.com/doc/refman/5.0/en/connecting.html
Says:
On Unix, MySQL programs treat the host name localhost specially, in a
way that is likely different from what you expect compared to other
network-based programs. For connections to localhost, MySQL programs
attempt to connect to the local server by using a Unix socket file.
So you have to
use "127.0.0.1" instead of "localhost" to use tcpip instead of sockets, or
enable sockets in mysql server config (socket connections are probably disabled and that causes that error on linux)
Second method is better - using sockets for local connections is better than TCP/IP (better performance), but you may have no privileges to mysql configuration on that server.
Try installing phpmyadmin or php5-mysql as in apt-get install phpmyadmin.

Categories