mssql_connect(): Unable to connect to server on windows server 2000 - php

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.

Related

Remote MySQL in Disk station connection refused

I am trying to log-in remotely to MySQL server which is running on my Disk station, over the network. I confirm that MySQL is running on the disk station, I have php running on the disk station and I can check via remote connection to disk station phpMyAdmin and MySQL queries are answered.
On my laptop, I have created the following PHP script and when I try to run this script on my laptop, I get the following error message
<?php // login.php
$hn = 'bio12' ; //disk station name
$db = 'mysql' ; //database I want to connect to
$un = 'mysqluser' ; // user name
$pwd = 'abctest123' ; // password for the user
$conn = mysql_connect($hn, $un, $pwd);
if(! $conn){
die('Could not connect') ;
}
echo 'Successfully Connected';
?>
Error message: Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\login.php on line 15
Could not connect
I have tried using the IP address instead of 'bio12' but without success.
Interesting enough, when I use the same code and try to connect to local mysql (I am running XAMP on my laptop) and using the 'localhost' instead of 'bio12' it works just fine.
What am I doing wrong?
You need to allow remote connections. Find line in your mysql config (my.cnf file)
bind-address = 127.0.0.1
and comment it with "#" at the beginning, please also see this thread: How to allow remote connection to mysql

How to do PHP to MS SQL connection?

I'm using xampp and my php version is php5.5.6 in WIN-7 os. I want to connect the MS SQL Server from my PC. I'm having MSSQL SERVER in my LAN. how to do that, I'm new to PHP?
Right from the manual - http://www.php.net/manual/en/function.mssql-connect.php
<?php
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$server = 'KALLESPC\SQLEXPRESS';
// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
?>
If this code does not work, then make sure you can ping the database server from the web server.

Access a MySql Database from PHP (not on localhost)

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

linux php connect to Server 2008 running MS SQL Server Express

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=.

using mssql_connect to connect to a DB in another server

We are using the below script.
Actually our DB is in one server (say www.server1.com) and the PHP file
containing the below connection string is in another server (say
www.server2.com)
If we place the PHP file containing the below script in the same server
where the DB exists that is www.server1.com/dbconnection.php it is working
fine.
But if we place the PHP file containing the below script in another server
www.server2.com/dbconnection.php it is not working. This displays the
error 'Something went wrong while connecting to MSSQL' Please advise.
Also to handle error if we use 'die('MSSQL error: ' .
mssql_get_last_message());' nothing displays just an empty page.
Please advise how to handle errors.
Script (dbconnection.php)
$server = 'xxx.xxx.xxx.x,xxxx'; //IP, Port
// Connect to MSSQL
$link = mssql_connect($server, 'username', 'password');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
// Connect to DB
$db=mssql_select_db("databasename",$link) or die("Unable to select
database ");
Thank You
How to get error message, I do not know, but if you are migrating your PHP app from windows server to linux (FTP servers are more usual on linux), you can try change:
$server = 'xxx.xxx.xxx.x,xxxx'; //IP, Port
to
$server = 'xxx.xxx.xxx.x:xxxx'; //IP: Port
As described in first parameter of manual: http://www.php.net/manual/en/function.mssql-connect.php

Categories