PHP sqlsrv_connect is not defined - php

I am using hostinger web hosting server and added sqlsrv extension in php configuration in hostinger account.
Hostinger technical team confirmed that below functions are enabled in my hostinger account.
[1792] => sqlsrv_connect
[1793] => sqlsrv_close
[1794] => sqlsrv_commit
...
But when I tried to connect to our remote mssql server using sqlsrv_connect, "Call to undefined function sqlsrv_connect()"
My test code is below.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$serverName = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$connectionInfo = array( "Database"=>"xxxxxxxxxxxx", "UID"=>"xxxxxxxxxxxx", "PWD"=>"xxxxxxxx");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
And the response of this php script is below.
Fatal error: Uncaught Error: Call to undefined function
sqlsrv_connect() in
/home/uxxxxxxxxx/domains/xxxxxxxxxxxx.xxxx/public_html/sql.php:8 Stack
trace: #0 {main} thrown in
/home/uxxxxxxxxx/domains/xxxxxxxxxxxx.xxxx/public_html/sql.php on line
8
Hostinger technical team said that it's code problem, and sqlsrv extension is enabled for my account.
Have you any experienced with this kind of issues ?
What's the solution for this ?
Thanks.

Related

php Call to undefined function sqlsrv_connect()

I have windows 10 64 bit and installed xampp version 7.3 and I am trying to connect with SQL server using my below code but it always gives me that error:
"Uncaught Error: Call to undefined function sqlsrv_connect()".
I have downloaded ODBC versions 11,13,17 and I downloaded dll drivers and located them in my "xampp/php/ext". also I have changed the extension in my php.ini file and tried every single extension with different versions but nothing works!
<?php
echo phpinfo();
$serverName = "ServerNAme"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"DB[![enter image description here][1]][1]");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
sqlsrv_close($conn);
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>

Uncaught Error: Call to undefined function sqlsrv_connect()

I installed xampp-win32-7.2.11-0-VC15-installer.exe, downloaded and extracted SQLSRV53.EXE to C:\xampp\php\ext, added
;extension=php_sqlsrv_72_ts_x64.dll
;extension=php_pdo_sqlsrv_72_ts_x64.dll
to php.ini and still get Uncaught Error: Call to undefined function sqlsrv_connect()
my code:
<?php
$serverName = "XXXXX\SQLEXPRESS"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"XXXX");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
1) php_sqlsrv_72_ts_x64 AND php_pdo_sqlsrv_72_ts_x64 should be 32 bit same as xampp
2) Also compatible with PHP version
In my case there were 2 php.ini files on wamp server. one of them is located at C:\wamp\bin\apache\Apachex.x.x\bin folder and when i tried to connect through sqlsrv_connect function, we are referring to the php.ini file in the apache folder.
So please check the php.ini in apache folder and enable the extension and test your connection with sqlsrv_connect.
Hope this will help.

Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www\Project\Demo.php on line 4

MS SQL server Connection to PHP Using Wamp Server, I Will follow this Step :
My System Windows 7 64-bit
installed Wamp Server 64-bit
SQLSRV32.EXE installed in C:\wamp\bin\php\php5.6.31\ext
wamp server PHP.ini file give extension
extension=php_sqlsrv_56_nts.dll
extension=php_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_nts.dll
Demo.php`
<?php
$serverName = "ZALA-PC\EURASIAN";
$connectionInfo = array("Database" => "Demo", "UID"=>"sa" , "PWD"=>"stcare#1");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>

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

I Have a big problem And I Wish get Solved for this problem here
I Try to Connect to Sql Server 2008 R2 using:
php 5.6.11
Xampp 5.6.3
Sql Server 2008 r2
Using sql server drivers for PHP (php_pdo_sqlsrv_56_ts.dl &
php_sqlsrv_56_ts.dll)
and my code to try connection is :
$serverName = "Mahmoud-HP\SQL2008R2"; //serverName\instanceName
$connectionInfo = array( "Database"=>"HR16", "UID"=>"Mahmoud", "PWD"=>"123" , "MultipleActiveResultSets" => false);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
but when run the page this message come to me
Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\testsqlserver\index.php on
What is solution for this problem
you have to use the SQL Server native driver for php.
Download from here:
https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=20098
Example Code:
$serverName = "tcp:ServerID.database.windows.net, 1433";
$connectionOptions = array("Database" => "DatabaseName",
"UID" => "Username#ServerID",
"PWD" => "password");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false)
{
die(print_r(sqlsrv_errors(), true));
}
EDIT
Make sure you load BOTH dll's listed:
extension=php_sqlsrv_56_ts.dll
and
extension=php_pdo_sqlsrv_56_ts.dll

Fatal error: Call to undefined function sqlsrv_connect() while sqlsrv dll's are loaded

i am getting Fatal error: Call to undefined function sqlsrv_connect() when i try to connect to database with this code and both dll's are present:
<?php
$serverName = "LOZANOVSKITLT\SQLEXPRESS";
$connectionInfo = array( "Muzicari"=>"Bend");
$conn = sqlsrv_connect( $serverName, $connectionInfo); //here it fails
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_close($conn);
?>
Below in the google drive link you will see screenshots for better information
Operating System: Windows 10 Pro 64-bit
System Manufacturer: Acer
Memory: 4096MB RAM
System Model: Aspire 5741
32bit WAMP installation
https://drive.google.com/folderview?id=0B_B7w46v8TbWTkZPdWVkTml4VFk&usp=sharing

Categories