sqlsrv_connect not found with wampserver2.5 and dlls copied - php

I have configured wampserver 2.5
Apache/2.4.9 (Win64) PHP/5.5.12
I want to connect to SQL Server with PHP.
i have read wampserver doesnt support by default, so i downloaded the dlls, php_pdo_sqlsrv_55_ts.dll & php_sqlsrv_55_ts.dll and copied the same to ext folder of php(\bin\php\php5.5.12\ext) and added the extensions in php.ini file.
After that i have written a simple php file to check connect,
$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 i am getting error "Call to undefined function sqlsrv_connect()"
can i know why this error is still coming. How i can resolve the same.???

Related

Call to undefined function sqlsrv_connect() - Troubleshooting

System Information
CMS: Wordpress
Web Server: XAMPP
PHP Version: 5.5.30
MS Management Studio 17
Goal
Establish MSSQL Database connection using PHP
What has been done
Downloaded SQLSRV Drivers
Copied files php_pdo_sqlsrv_55_nts.dll and php_pdo_sqlsrv_55_ts.dll to the directory C:\xampp\php\ext
Added the following lines to the dynamic extensions part in the php.ini file: extension=php_pdo_sqlsrv_55_ts.dll and extension=php_pdo_sqlsrv_55_nts.dll
Restarted Web Server
Confirmed sqlsrv is listed in phpinfo()
Code
$serverName = "technology-pc\sqlexpress";
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"example_db");
$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));
}
Error
Call to undefined function sqlsrv_connect()
You have added the PDO variant of SQLSRV drivers to the extension list, but have not added the base drivers php_sqlsrv_55_ts.dll.
Add to the php.ini:
extension=php_sqlsrv_55_ts.dll
or
extension=php_sqlsrv_55_nts.dll
Also, you really should be using either the Thread-Safe (_ts.dll) or Non-Thread-Safe (_nts.dll) versions of the driver, not both. I believe that, as you are using an Apache Server, you should be using the Thread-Safe versions. So you php.ini should have:
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
You probably edited the wrong php.ini file. Check the right php.ini file with php info.
You can use this script:
<?php echo phpinfo(); ?>
Or if you have CLI access type php -i to get the info listed.
Check for the right path of your php.ini file.
Try below code to connect mssql database
$server = 'dburl.com\MSSQLSERVER, 1433';
$username = 'uname';
$password = 'password';
$connectionInfo = array( "Database"=>$database, "UID"=>$username, "PWD"=>$password,"ReturnDatesAsStrings"=>true);
$conn = sqlsrv_connect( $server, $connectionInfo);

No connection made to MS SQL via PHP

I'm trying to connect to a MSSQL database through PHP, but the connection doesn't seem to be ever made or it times out, not sure. When I load the file via localhost, I get the check1 debug statement but not check2. What am I missing? I can connect and navigate the database via MS Server Management Studio.
My environment
PHP Version 5.2.6
Window 7 64-bit
In my php.ini file, I added the following and verified those drivers are in the proper extension_dir.
extension=php_pdo_sqlsrv_53_ts.dll
extension=php_sqlsrv_53_ts.dll
Code below:
<?php
print_r("check1");
$serverName = "servername\instance";
$connectionInfo = array( "Database"=>"dbname", "UID"=>"user.name", "PWD"=>"abc$1s");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
print_r("check2");
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
edit:
Tried again after installing version 3 PHP SQL drivers and with PHP version 5.4.32 with no luck.

How to install msodbcsql in microsoft AZURE server (PaaS)

Okay, so basically I have now deployed an Web App in Azure, but I cannot seem to make it to connect to a separate SQL SERVER. I have provided all the desired App settings for the connection but it seems no good.
Now I search for possible causes:
PHP ext dlls are missing for msodbcsql which are
php_pdo_sqlsrv_56_ts.dll
and
php_sqlsrv_56_ts.dll
I already added this dll's and referenced them accordingly base on this document Configure via ini settings
Now the uncertainty that msodbcsql is installed in Azure.
Now this is what I am having problem with.
So in my case in number 2 I tried copying the installer to Azure D:/home/
and run this in the command line
msiexec /quiet /passive /qn /i msodbcsql.msi IACCEPTMSODBCSQLLICENSETERMS=YES ADDLOCAL=ALL
which is suppose to install the .msi installer but i always get an
ACCESS IS DENIED
error.
is there another way around??
Basically Azure has already set up extension php_sqlsrv.dll & php_pdo_sqlsrv.dll for us, so we ourselves do not need to install any driver to connect SQL SERVER.
You could check the php.ini file which can be found at D:\local\Config\PHP-<version>\php.ini with Kudu console to confirm that.
Also, you can check that with phpinfo() function in your application.
And I have tested it with the following lines of code and got it worked.
<?php
$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));
}
?>

Cannot connect PHP to SQLServer 2012

I'm using xampp and I'm trying to connect my PHP project to SQL Server to make reports. But there's a conflict with sqlsrv_connect() function.
My version of PHP installed in XAMPP is 5.6.23 and my connection file contains this:
<?php
$serverName = "MyserverName\MyinstanceName"; //serverName\instanceName
$connectionInfo = array("Database"=>"Database_Example");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn ) {
echo "Conexión establecida.<br />";
}else{
echo "La conexión no se pudo establecer.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
Also, I have downloaded the next files and I have extracted in "C:\xampp\php". PHP dll's
And I have added to "php.ini" file this code:
extension=php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_ts_x64.dll
I´ve tried too with the exact version of the driver for my PHP and it doesn´t work.
Drivers Version
And this is the error that appears when I'm trying to connect:
Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\Inventory\conexion.proc.php
I have solved my own problem! I write the answer for someone with the same problem.
The version of the driver have to be the same of your PHP, not superior. You have to extract the dll files in "C:\xampp\php\ext" not in "C:\xampp\php".
After that another problem will appear:
ODBC Driver 11
You have to dowload ODBC Driver 11 on this link: https://www.microsoft.com/en-us/download/confirmation.aspx?id=36434
And then when the driver will be installed, your code with queries will work!

i get a Fatal error when i try to connect mssql using php in wampserver

I'm using Wampserver (32bit & php 5.4I)2.4 *in windows 64bit*, will i install the 32bit becuse i need a connection to the MSSQL which required that as i know so far.
i downloaded the Microsoft Visual C++
and the php is a thread safe
so i added the two .dll files (php_pdo_sqlsrv_54_ts , php_sqlsrv_54_ts*) to the C:\wamp\bin\php\php5.4.16\ext*, then added them in the php.ini ( extension=php_pdo_sqlsrv_54_ts and extension=php_sqlsrv_54_ts), then restarted the wampserver
finally i gett an error says "Fatal error: Call to undefined function sqlsrv_connect()"
the code that i use is :
<?php
$serverName = "serverName\instanceName";
$connectionInfo = array( "Database"=>"DB NAME");
$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));
}
?>
could anyone tell me what did i do wrong to cause this error?
Use phpinfo() to see if the extension was loaded correctly.
If yes, see the error log for any issues encountered when starting apache (W*A*MP).
If yes, then the extension binary is wrong or you forgot to enter the file extension (.dll on Win, .so on Linux) in the php.ini.

Categories