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));
}
?>
Related
I am trying to connect my SQL server with PHP using Xampp. I have already uploaded dll files in the ext folder but I am unable to connect it.
My PHP version is 7.2.6.
Uploaded dll files are - php_pdo_sqlsrv_72_ts.dll, php_sqlsrv_72_ts.dll.
I have written this code to connect my SQL database with PHP-
<?php
$serverName = "INDO-SERV\SQLEXPRESS,1443";
$uid = "sa";
$pwd = "XXXXXX";
$databaseName = "web";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>$databaseName);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_close( $conn);
?>
I am getting this error when I had tried this-
Fatal error: Uncaught Error: Call to undefined function
sqlsrv_connect() in C:\xampp\htdocs\biometric\db.php:7 Stack trace: #0
{main} thrown in C:\xampp\htdocs\biometric\db.php on line 7.
Anyone has an idea where I am doing wrong or how to connect with the database.
Installation of PHP Driver for SQL Server (sqlsrv and/or pdo_sqlsrv PHP extensions) can be done following the next steps:
Based on Microsoft PHP Drivers for SQL Server Support Matrix download appropriate version of this driver. In your case - version 5.2 or 5.3 (32-bit or 64-bit also depends on PHP version).
Download and install an appropriate ODBC driver - see System Requirements for the Microsoft Drivers for PHP for SQL Server
Load PHP Driver for SQL Server as PHP extension.
Restart Apache
Check the configuration with <?php phpinfo();?>. There should be a section with name pdo_sqlsrv (if you use PDO) and/or sqlsrv (without PDO).
my XAMPP version is 7.0.13
1- Download and Install "SQLSRV40.EXE" on this path:
D:\xampp\php\ext
2- Download and Install "msodbcsql.msi"
3- Edit file ":\xampp\php\php.ini" and add this extensions :
extension=php_sqlsrv_7_ts_x86.dll
extension=php_pdo_sqlsrv_7_ts_x86.dll
extension=php7ts.dll
4- restart xampp
Note: "SQLSRV40.EXE" Contain this extensions:
php_sqlsrv_7_ts_x86.dll , php_pdo_sqlsrv_7_ts_x86.dll , php7ts.dll
Download driver from:
https://download.microsoft.com/download/f/4/d/f4d95d48-74ae-4d72-a602-02145a5f29c8/SQLSRV510.ZIP
Unzip the files
Copy the dll files in C:\xampp\php\ext\
Open with your favourite editor the file php.ini located in C:\xampp\php\
Insert the extensions:
extension=pdo_sqlsrv_74_ts_x64
extension=sqlsrv_74_ts_x64
Restart Apache and PHP
For the new comers;
You can setup driver and integrate it as in this video explains so in a nutshell;
You should find drivers for php - sql server integration depending to your environment (versions) at links and download the driver that suits for your environment.
You should move the driver file (.dll for windows case) to php/ext folder.
You need to change php.ini as entering a new extension (for example extension=php_sqlsrv_7_ts.dll) by giving your exact file name you have moved to php/ext.
Restart your local server and you should see this extension in phpinfo(), if you can see it's there, you can connect to your db with your credentials and it's done.
Credits goes to creator of the video (applause) :)
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);
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.
I am trying to connect to a mssql server using php. The sql server is on a different machine in the network and I have XAMPP installed in my machine. I don't have microsoft sql installed in my server.
I have downloaded the sqlsrv drivers for PHP and then in my php.ini file added the extension extension=php_pdo_sqlsrv_55_ts.dll under windows extension.
Added the php_pdo_sqlsrv_55_ts.dll file inside the php\ext\ folder of my XAMPP installation.
After restarting apache phpinfo(); shows that the sqlsrv driver is enabled
PDO support enabled
PDO drivers mysql, sqlite, sqlsrv
This is my code
<?php
$serverName = "192.168.100.102, 1433";
$connectionInfo = array( "Database"=>"ATP", "UID"=>"raihan", "PWD"=>"temp123#");
$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 on executing I get this error
Fatal error: Call to undefined function sqlsrv_connect() in
D:\xampp\htdocs\database\index.php on line 4
Why this error? And how do I go about connecting to mssql server using php?
php\etc\ sounds like wrong folder, try put in php\ext\ folder
Note extension=php_pdo_sqlsrv_55_ts.dll is used by PDO class
Go to https://www.microsoft.com/en-us/download/details.aspx?id=20098
Select download by your PHP version:
Select SQLSRV30.EXE if use SQL Server 2005
Select SQLSRV31.EXE or SQLSRV31.EXE if use SQL Server 2008
After download, extract dlls
If you use php with ThreadSafe (apache2handler -- more probable) copy php_sqlsrv_55_ts.dll fot ext folder
For use sqlsrv uncomment (or put) this line in php.ini extension=php_sqlsrv_55_ts.dll (or extension=php_sqlsrv_55_nts.dll for no-thread-safe)
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.