i can connect from client PC to SQL Server Express using the following creds. in mgnt sudio:
server: 192.168.44.96\sqldb
auth: windows auth
user name: domain\user
pw: 1234!
Have a LAMP server trying to connect to the above SQL server, here's what the PHP looks like:
$server = '192.168.44.96\sqldb';
$username = 'domain\user';
$password = '1234!';
$database = 'testing123';
$connection = mssql_connect($server, $username, $password);
if($connection != FALSE){
echo "Connected to the database server OK<br />";
}
else {
die("Couldn't connect" . mssql_get_last_message());
}
if(mssql_select_db($database, $connection)){
echo "Selected $database ok<br />";
}
else {
die('Failed to select DB');
}
the page displays 'couldn't connect' and the error.log says "unable to connect ot server: 192.168.44.96".
I have also set mssql.secure_connection = On in php.ini and restarted apache2.
any thoughts?
thanks!
I can't comment on the PHP part, I only know SQL Server.
But I can tell you: That's not how Windows authentication works.
You can't use Windows authentication and then pass user name and password explicitly to the server. You need to do one of these:
Use SQL Server authentication and pass user name and password explicitly
Use Windows authentication and do not pass user name and password - you will connect automatically with the active Windows user.
Since you're using a Linux server, I'm pretty sure that you can't use Windows authentication. So you have to use SQL authentication (which needs to be enabled on a fresh SQL Server installation), and you have to create an user on the SQL Server.
If you have a default sqlexpress installation you probably need to configure your sql server to allow remote access connections.
Also I don't know if you can connect with windows auth. At your sql server you can also setup sql authentication and use uid=;pwd=.
Related
I am running mysql on a linux server. I have the linux server IP and mysql runs on localhost on that linux server. Now how do I access mysql running on localhost server remotely?
I can do this by ssh into linux server then running mysql, but how would I do it with in a php script? For example...
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username,
$password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
(this script only connects to mysql directly which is not possible remotely)
In my script I would need to access linux server then mysql server unless there is a way to access mysql directly (remotely). How is this achievable?
You need change bind address in my.cnf and restart your mysql service.
Official documentation:
https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_bind_address
If the address is 0.0.0.0, the server accepts TCP/IP connections on all server host IPv4 interfaces.
By default all connections restricted localhost.
In order to access your mysql instance from your server; you need to install workbench (or some other mySql explorer) on your development machine.
Create a connection to mysql instance using server ip address as host name and provide username and password to open connection. If every thing goes well you will see your databases in explorer.
I have application with php. I want to connect on sql server 2000
This is my code:
$server = '10.0.0.26';
// Connect to MSSQL
$link = mssql_connect($server, 'username', 'password');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
But I have error like
Message: mssql_connect(): Unable to connect to server: 10.0.0.8. I
make sure that i use correct username, password and ip.
When I use this code to connect sql server 2012. I did't get any error.
I run my php using apache on linux.
The first parameter should be SERVERNAME not Server's IP as it is mention in the PHP DOCS
eg ( from php manual)
$server = 'KALLESPC\SQLEXPRESS';
// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
Check your php.ini file:
; Use NT authentication when connecting to the server
mssql.secure_connection = On
If you have secure_connection = On, make sure that you provide valid credentials in the properties for Apache service in the System Services box. Then you should not send DB username and password from your script to MSSQL Server.
If you want to use specific credentials from a PHP script, then set
mssql.secure_connection = Off
in your php script.
I'm trying to connect to a local SQL server from a PHP srcipt using odbc_connect, but I can't log in.
This is my code so far:
$user= "PC_NAME\PC_USER";
$password="";
$dsn = "Driver={SQL Server};Server=MyServer;Database=MyDatabase;Integrated Security=SSPI;Persist Security Info=False;";
$link = odbc_connect("$dsn", $user, $password);
Can you see anything wrong?
I had a bad configuration in my SQL Server. I had to allow SQL login besides the default Windows login
there's this server:
http://phpmyadmin.pvdata.fr/index.php ,
I can connect to it knowing the username and password and Server Choice.
Once I connect to it, it shows under MySql the following information: (I'm Translating from French)
Server: sql6 (sql6 via TCP/IP)
Server Version: 5.0.92-87
Protocol Version: 10
Username: pvdata#10.5.1.3
Character for MySql: UTF-8 Unicode (utf8)
So I tried using the following code in order to connect to the Database:
<?php
// Create connection
$username = "pvdata";
$password = "xxxxxxxx";
$hostname = "10.5.1.3";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
?>
But it didn't work, it's saying: "A connection attempt failed because the connected party did not properly respond after a period of time".
What am I doing wrong?
Go to your phpMyAdmin installation and look for the file config.inc.php. Open that file, and check which hostname / ip is being used for SQL6. That is the IP you should use for your mysql_connect()
This is most likely a firewall issue. Most 3rd party hosts don't allow you to access MySQL from 'the outside'.
You can do this if you manage the MySQL server yourself or if you have a host that doesn't deny you to access the database from another machine, but in regular web hosting, this is not common.
You need to search, google helps a lot, also you need to connect to an ip/domain and port of your MySQL server.
For this, you need to know what is the port of your mysql server.
Look this answer from link
<?php
mysql_connect("mysite.com:3306", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
to check if you have coneccion, try in console:
shell> mysql --host=remote.example.com --port=3306 //3306 is the
defaul port for MySQL
http://dev.mysql.com/doc/refman/5.0/en/connecting.html
I am attempting to connect to a Microsoft SQL server db using PHP (in IIS). The user/pass provided in the code is an AD account that can access the database via ODBC in Access just fine.
$serverName = "servername";
$connectionInfo = array( "Database"=>"dbname", "UID"=>"myuser", "PWD"=>"mypass");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br /><pre>";
die( print_r( sqlsrv_errors(), true));
}
The username and password are valid, as are the server name and database name. But this is returning the error:
[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'myuser'.
For the username (which is a valid user in AD, and I can connect/link to this database using Access) I've also tried:
DOMAIN.ORG\myuser
DOMAIN.ORG\\myuser
myuser#DOMAIN.ORG
My domain user (myuser) has admin privileges to that server via AD. But that returns the same Login failed error. Is there something I'm missing? I can connect to this same db using Access without a problem (under the same user).
The way I connect in Access is an ODBC Data Source for the local user. The Data Source is set to authenticate "With Windows NT authentication using the network login ID". How can I do that in PHP?
Is this impersonation configuration the possible cause?
PHP is running under the user nt authority\iusr
If it was trying to login using iusr wouldn't the error message say so?
I've tried creating a Data Source on this machine called "TestDS" and using the code:
$conn = odbc_connect("TestDS", "", "");
But that gives me:
The specified DSN contains an architecture mismatch between the Driver and Application, SQL state IM014 in SQLConnect
Machine1 is a client trying to access a webpage (where the PHP code is on Machine2) and the code on Machine2 is making the SQL connection to Machine3 (servername).
"Windows Security" in SQL Server connections is enabled by specifying "Trusted Connection=SSPI" in the connection string. No username or password is stored in the connection string (that's only for "SQL Server Security"). The process running PHP (presumably php_cgi.exe itself) must run under a Windows (either local or AD) that has a Windows login registered on the SQL Server.
Under IIS php_cgi.exe runs under the user identity of the application pool. If you have a heterogenous security environment I suggest creating an IIS application pool just for this single website.