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.
Related
I am working on php website for my class and I am having trouble connecting to my schools database server when i upload my files to my schools website. My school only has a database server on HediSQL and Workbench and I am currently using HeidiSQL to access the account database my school created for me.
I am currently using this code to try and connect.
$host='school.edu';
$user='user';
$pass='pass';
$db='db';
$port='3306';
mysqli_connect($host, $user, $pass, $db, $port);
Using this i can connect to my schools database just fine when i am on my own computer and run it through localhost, but as soon as i upload my website using SSH to my schools server, the website cannot connect to the database.
Any help would be appreciated! Thank you.
Edit: I am using php, heidiSQL, and SSH secure file transfer.
$host='localhost';
$user='user';
$pass='pass';
$db='db';
$port='3306';
mysqli_connect($host, $user, $pass, $db, $port);
Please make changes to the $host variable.
$host = 'localhost';
host is always use as localhost on server
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 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 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.
I am trying to use mysqli_connect as such:
$host = "ftp.tatiana-renae.com";
$user = "tatiana";
$password = "********";
$dbname = "********";
$connection = mysqli_connect($host, $user, $password, $dbname);
but I get this error:
Database connection failed: Can't connect to MySQL server on 'ftp.tatiana-renae.com' (111) (2003)
I know mysqli_connect works differently than mysql_connect but I can't figure out what to do for mysqli_connect to make it happy. Any ideas?
Error 111 is "connection refused". One candidate explanation is that MySQL is not "listening" on the network, but only the TCP loopback address.
Check the my.cnf for the server, and check if it contains lines like this:
skip-networking
or
bind_address=127.0.0.1
If your PHP is running on the same server as MySQL, you can try using '127.0.0.1' for the host, in place of 'ftp.tatiana-renae.com'.
Is the MySQL server running? Can you connect to it using the mysql command line interface?
There's several other possibilities; but there's not enough information provided about you environment for us to accurately diagnose the problem. We're just guessing.