connection error while using php and sql server 2008 - php

Connection failed: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
as i establish connection between my computer and remote machine using "php" and sql server 2008 respectively. i got this error.
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "complaint";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

You must have a defined servername, username and password. If the server is local than use "localhost" if it is a remote server use IP "X.X.X.X"

Related

Connecting laptop MS SQL Express server using PHP script on Hostinger

[First time trying the code]I am trying to use a simple PHP file, that I uploaded to Hostinger, to connect and query my laptop's Microsoft SQL Express Server (to test the website, as the database is large to upload to the Hostinger database). The following Ms SQL connect gives an "HTTP ERROR 500" page error (*possibly because Hostinger does not support MsSQL):
<?php
$host = 'DESKTOP-SL59JDD\SQLEXPRESS';
$dbname = 'FXDatabase';
$username = 'sa';
$password = 'test123';
$dbhandle = mssql_connect($host, $username, $password)
or die(“Couldn’t connect to SQL Server on $host”);
?>
Also attempted MySQL connect as followed, which gives a "Connection failed: php_network_getaddresses: getaddrinfo failed: Name or service not known" error.
$host = 'DESKTOP-SL59JDD\SQLEXPRESS';
$dbname = 'FXDatabase';
$username = 'sa';
$password = 'test123';
$conn = mysqli_connect($host, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
} else {
echo "Connection Successful!";
}
is there a permission on the Microsoft SQL Express server that I am missing to give to the sa user?

php mysql connection failed The server requested authentication method unknown to the client

$servername = "localhost";
$username = "jaskaran";
$password = "India#123";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
jaskaran has all access mysql and when i try with
mysql -u jaskaran -p it is working fine by when i try with php it does not why
error is The server requested authentication method unknown to the client
even i try this also
ALTER USER 'jaskaran'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'India#123';

How can I bypass error 111 MySQL in PHP connection?

I have bought a database MySQL to use on my domain/host.
I can connect to the database via wampserver (localhost) without problems.
But when I am trying to connect to the host website it gives me an error.
Connection failed: Can't connect to MySQL server on 'mysql-******.net' (111 "Connection refused")
My code:
<?php
$servername = "mysql-*********.net";
$username = "username8954";
$password = "dolphyn1235";
$dbname = "animals";
$dbServerPort = "26313";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $dbServerPort);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Any ideas how to solve this?
Check in your MySQL Server configuration files (my.cnf), find bind-address = 127.0.0.1 then comment them with # at the begining of the line. and then restar your MySQL.

Not able to connect to remote mysql

my code is as below
$dbhost = 'example.com';
$dbuser = 'dbusername';
$dbpass = 'dbpassword';
$dbName='dbname';
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbName);
// check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
after i execute code getting below error
Connection failed: Connection refused
Warning: mysqli::__construct(): (HY000/2002): Connection timed out in /home/public_html/test/remote.php on line 8
Connection failed: Connection timed out
I don't know your environment, but my experience is that most publicly accessible webservers do not expose the SQL-database to the public, so the port is probably blocked. If you control the server, then you can probably find something in the firewall, but if you are using something like shared hosting, then you can really only try the helpdesk.

How to connect to my remote Mysql Database via Xampp

I am using Xampp to update my website and since I have added a Mysql database I have the error further down locally while it works fine online.
I'm using the code below to connect to my database:
<?php
$servername = "myservername";
$username = "myusername";
$password = "mypassword";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
http://localhost/connectdb.php
Result:
Connection failed: php_network_getaddresses: getaddrinfo failed: No
such host is known.
http://example.com/connectdb.php
Result:
Connected successfully
So there must be some configuration to do in Xampp to access a remote database or do I need to ask my host to whitelist my private IP Address? My host is OVH.
Thanks for your help

Categories