ODB_CONNECT() not working on windows server 2008 R2 - php

I am trying to make ODBC connection from windows server 2008 R2, but it shows me this error:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC SQL Server
Driver][DBNETLIB]SQL Server does not exist or access denied., SQL
state 08001 in SQLConnect in
C:\xampp\apps\wordpress\htdocs\wp-content\themes\Divi\cargo_consignment_tracking.php
on line 30
My php version is 7.0.9
My connection string to connect with the server
$server = 'SERVER_IP_ADDRESS';
user = 'USERNAME';
$pass = 'PASSWORD';
$port = '1433';
$database = 'cargo_web';
//connection string
$connection_string = "DRIVER={SQL Server};SERVER=$server;$port;DATABASE=$database";
$conn = odbc_connect($connection_string,$user,$pass);
Its working on my localhost server, but not on windows server 2008 R2.
My phpinfo() contains ODBC part and I have enabled odbc connection in php.ini with these lines
extension=php_pdo_odbc.dll
extension=php_odbc.dll
Why am I facing this issue on the server ??

Related

Fatal error: Call to undefined function sqlsrv_connect() in php 5.6.25

OS: Windows 8.1
Web Server: WAMPSERVER 3.0.6
PHP Version: 5.6.25
Goal: To establish MYSQL Database connection using PHP
What has been done:
Downloaded SQLSRV Drivers (SQLSRV32.EXE)
Copied files php_pdo_sqlsrv_56_ts.dll and php_sqlsrv_56_ts.dll to the directory "C:\wamp64\bin\php\php5.6.25\ext"
extension_dir = "c:/wamp64/bin/php/php5.6.25/ext/"
Added the following lines to the dynamic extensions part in the php.ini file:
extension=php_pdo_sqlsrv_56_ts.dll
extension=php_sqlsrv_56_ts.dll
Restarted Web Server
But: phpinfo() is not listed in sqlsrv()
Code:
$myServer = "(local)";
$myUser = "sa";
$myPass = "pass";
$myDB = "example_db";
$connectionInfo = array("Database"=>$myDB, "UID" => $myUser, "PWD" => $myPass);
$conn = sqlsrv_connect($myServer, $connectionInfo);
Error:
Fatal error: Call to undefined function sqlsrv_connect() in
C:\wamp64\www\optimum_p\common\dbconnect.php on line 6
As per OP's comment:
The problem was WAMP, to fix the problem:
uninstall WAMP
install XAMPP
Problem solved.

How to connect from cakePHP3 to MSSQL Server

(I develop on a Windows System with XAMPP and use cakePHP3)
I want to connect from my cakePHP3 Localhost application, to a external SQL Server (installed on a external Windows Server 2012 r2).
In my app.php I config my Server and that is how I test the connection:
try {
$connection = ConnectionManager::get('sqlServer');
$connected = $connection->connect();
}catch (Exception $connectionError) {
echo "not";
}
echo "connected";
On testing I get this error:
A Database connection using was missing or unable to connect.
The database server returned this error: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
So I go to my Server and Installed the needed extensions (ODBC Driver 11 for SQL Server). But I get still the same Error.
Is it possible to connect to the external Server from Localhost? Or did I make a mistake?

SQL Server 2014 Connection string is not valid [87] in php

I upgraded from SQL SERVER 2008 from SQL SERVER 2014.
I am already using SQL SERVER 2008 with PHP. After the upgrade from SQL SERVER 2008 to SQL SERVER 2014 it doesn't seem to be working. It's showing the following error:
[Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network
Interfaces: Connection string is not valid [87]
[Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
[Microsoft][ODBC Driver 11 for SQL Server]A network-related or
instance-specific error has occurred while establishing a connection
to SQL Server. Server is not found or not accessible. Check if
instance name is correct and if SQL Server is configured to allow
remote connections. For more information see SQL Server Books Online.
change the \ in $server
and first give UID & PWD then Database
$server = "servername\instancename";
$connectionInfo = array( "UID"=>"", "PWD"=>"****", "Database"=>"", );
$conn = sqlsrv_connect( $server, $connectionInfo );
if ($conn === false)
die("<pre>".print_r(sqlsrv_errors(), true));
echo "Successfully connected!";
this will working..

Error connecting to MSSQL using PHP

I am receiving an error as below:
PHP Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]SQL Server
Network Interfaces: Connection string is not valid [87]. '
My codes are as follow:
$this->link = new PDO(
"sqlsrv:server=$this->serverName:$this->port;Database=$this->db",
"$this->uid",
"$this->pwd"
);
I wish someone can enlighten me on what is causing this error. Before that I was using dblib instead of sqlsrv.
"dblib:host=$this->serverName:$this->port;dbname=$this->db"
I am using XAMMP with Apache 2.4.12 and PHP 5.5.24 (they are all x86). I have php_pdo_sqlsrv_55_ts.dll and php_sqlsrv_55_ts.dll. I am also using Microsoft ODBC Driver 11 for SQL Server-x64.
Change it to:
$this->link = new PDO(
"sqlsrv:Server={$this->serverName},{$this->port};Database={$this->db};",
$this->uid,
$this->pwd
);
The default SQL Server port is 1433. Note the curly brackets, they allow for class variables.

php_connect to odbc source produces TNS:could not resolve service name error after Xampp reinstall

I just updated my Windows Xampp install to get the latest PHP version and after the reinstall my web app is giving me the following error when trying to connect to an Oracle data source via the Microsoft ODBC driver for Oracle.
Warning: odbc_connect(): SQL error: [Microsoft][ODBC driver for
Oracle][Oracle]ORA-12154: TNS:could not resolve service name, SQL
state 08001 in SQLConnect in C:\xampp\htdocs\webapp\connections\db.php
on line 34
The code I'm using for this is;
$dsn = 'dsnname';
$user = 'username';
$pass = 'password';
$conn = odbc_connect($dsn, $user, $pass, SQL_CUR_USE_ODBC);
This was working fine before I did the Xampp update and now suddenly it's not working. I think I had this problem once before but I'm convinced it was solved by adding the SQL_CUR_USE_ODBC cursor.
Anyone got any ideas on what could be wrong?

Categories