I would like to connect to by Azure SQL database by using a PHP-Script. I execute the following script by using LAMP:
<?php
$serverName = "tcp:***.database.windows.net, 1433";
$connectionOptions = array("Database" => "TryMe",
"UID" => "***#serverID",
"PWD" => "***");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false)
{
die(print_r(sqlsrv_errors(), true));
}
?>
Of course I checked the firewall rules on Azure. I allowed my IP to access the server.
But I'm getting the error message:
GET http://localhost/Ionic/test.php in the web console.
What I'm doing wrong?
Thanks for your help!
The function sqlsrv_connect requires the Microsoft Drivers for PHP for SQL Server which is only enabled in Windows system. As you are working in LAMP environment, you can try to use ODBC extension and Microsoft's SQL Server ODBC Driver for Linux.
Related
Oke soo as the title said,
I have SQL Server 2005 installed on my windows 7 at home, and I have a website which is using linux (Ubuntu 14.04, can be upgraded if necessary),and the questions is
How to setup remote connection for SQL Server
What kind of driver or addons that I need to use for PHP on linux? SQLSRV ? is the driver safe to use?
Example for the driver that used to connect to SQL Server
And I see that people use ip to connect remotely, how do I get the ip for connecting to my own pc?
To setup remote connections follow the instructions here: https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-remote-access-server-configuration-option
Yes the driver is safe. Getting started instructions here: https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows/
Example code
<?php
$serverName = "localhost";
$connectionOptions = array(
"Database" => "SampleDB",
"Uid" => "sa",
"PWD" => "your_password"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn)
echo "Connected!"
?>
You can get ip from ipconfig
I am working on a PHP project where I have to create an API to fetch data from client's MS SQL server. I am doing it as-
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server_ip;Database=$databse;", $username, $password);
Its working on my localhost(might be because I have SQL Server install on my system, but not sure). But does not work on hosting server. It gives error-
[unixODBC][Driver Manager]Can't open lib 'SQL Server Native Client 10.0' : file not found
I have even tried -
$serverName = $server_ip;
$connectionInfo = array( "Database"=>$database, "UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$conn does not return anything.
Is there any other alternative?
I have even got odbc driver install.
There is an alternative (extension) called php-sybase. I am using it successfully to connect to various (versions) MSSQL databases with different php versions, to mention just: 5.6 and 7.0.
I am trying to fix an error while trying to connect to MSSQL using PHP on my windows server running IIS.
The error that I am getting is - ODBC error.
Sorry can't copy the error text here and hence the image.
I have PHP 5.6 configured and working. The necessary dll files are there in the php extensions folder. They're also configured in the ini file.
Extensions used for the MSSQL connection are:
extension=php_sqlsrv_56_nts.dll
extension=php_pdo_sqlsrv_56_nts.dll
I am using the below sample code to connect to the mssql db:
<?php
$servername = "ServerName";
$conninfo = array ("Database" => "DBName", "UID" => "UserName" , "PWD" => "Password");
$conn = sqlsrv_connect($servername, $conninfo);
if($conn){
echo "Connection Established."
}else{
die(print_r(sqlsrv_errors(), true));
}
?>
The connection always gives me the error shown in the image attached.
I have been stuck with this for quite a few days and haven't been able to get this resolved.
Any help would be greatly appreciated.
I am trying to connect PHP with MSSQL Server 2012. But unable to establish connection. I've latest version of php installed in my windows 7 PC. I tried to run <?php phpinfo(); ?> php script which is working fine but when I tried to connect MS SQL Database, I am unable to connect. Here's my simple php script to establish connection :
<?php
$server = "ADMIN-PC\admin";
$options = array( "UID" => "sa", "PWD" => "password123", "Database" => "Example");
$conn = sqlsrv_connect($server, $options);
if ($conn === false)
die("<pre>".print_r(sqlsrv_errors(), true));
echo "Successfully connected!";
sqlsrv_close($conn);
?>
Anything wrong with the code..?? Also search on google, tried other examples and gone through php manual but same issue. Please suggest me solution.
I'm having a lot of trouble trying to connect to a remote SQL Server from my local test environment. I can connect to the server using Toad for SQL Server, but I'm not sure why it's not working through PHP. Here's what I have:
$connectionInfo = array("Database" => "db",
"UID" => $user,
"PWD" => $pwd);
$connection = sqlsrv_connect("ip address", $connectionInfo);
if(!$connection) //error message
I've tried every possible combination I could think of - using the server/instance name, explicitly giving the port (1433), using Windows authentication by removing UID and PWD - all of which work fine with Toad. I don't know what else I can try, or what I'm missing.
Any assistance is appreciated.