Uncaught Error: Call to undefined function sqlsrv_connect() - php

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.

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));
}
?>

PHP sqlsrv_connect is not defined

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.

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));
}
?>

connect to SQL Server Database with PHP

I want to connect to a specific database on SQL Server Through PHP. On WAMP Server, I have PHP 5.6 installed so I downloaded SQLSRV32.EXE (Microsoft Drivers for PHP for SQL Server) then I copied these files in C:\wamp64\bin\php\php5.6.25\ext
IN php.ini, I added
extension=php_sqlsrv_56_nts.dll
extension=php_sqlsrv_56_ts.dll
But when i check phpinfo() on browser i don't see the sqlsrv module listed.
When i try to connect to my SQL Server Database I get this error
Fatal error: Call to undefined function sqlsrv_connect()
Here is my code
<?php
$serverName = "PC0CFEP2\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"=>"test");
$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));
}
?>
I was checking my solutions on different forums and I tried many but I still can't get it work. I am sure it's in some settings but i couldn't find out what could be the issue.
Any suggestion please ? Thank you very much.
At First, Please run MSSQL server database.
In php.ini file, Please added below code
extension=php_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_ts.dll
and keep two dll file \ext folder
To connect database , try
$serverName = "serverName\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$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));
}
Remove "php_" prefix:
extension=sqlsrv_56_ts.dll
extension=pdo_sqlsrv_56_ts.dll
This worked for me. Thanks for asking this question.

PHP program to connect to SQL Server

I've been doing a project in PHP(xampp) which requires to connect to a SQL Server database.
I've already done things like downloading and installing SQLSRV30.exe in C:\xampp\php\ext folder and creating a simple program which determine whether the program is already connected or not but still couldn't figure it out the problem that i encountered.
$server = "IDEA-PC\SQLEXPRESS";
$dbGet = array("Database"=>"LogboxDB");
$con = sqlsrv_connect($server, $dbGet) or die (sqlsrv_error());
if(!$con)
{
die(print_r(sqlsrv_errors(), true));
}
else
{
echo 'Connected';
}
Here is my error.
Fatal error: Call to undefined function sqlsrv_connect();
How can I get rid of this problem?
You need to enable the extension support to use the MSSQL server in PHP. It can be enabled by editing the php.ini as follow.
extension=php_sqlsrv.dll
You can donwload the package from http://docs.gurock.com/testrail-admin/howto-installing-sqlsrv
Try This
$serverName = "192.168.1.223, 1433"; //serverName\instanceName - change it as yours
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"LogboxDB", "UID"=>"username", "PWD"=>"password");
$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));
}

Categories