Connecting from localhost to cloud database I get this error - php

When I connect from localhost I get this error
Warning: mysqli::mysqli(): (HY000/2002): 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. in C:\xampp\htdocs\vici\index.php on line 9
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.
here is my code
$servername = "27.111.132.11";
$username = "root";
$password = "123";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

MySQL connection driver does not get any meaningful server at the location of localhost. So use,
'hostname' => '127.0.0.1'
rather than
'hostname' => 'localhost'

Related

Error while reading greeting packet on connection of php with mysql using mysqli

<?php
$conn = new mysqli('localhost','root', '', 'votesystem','8080');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
Errors returned are:
Warning: mysqli::__construct(): Error while reading greeting packet. PID=14576 in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
Fatal error: Maximum execution time of 120 seconds exceeded in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
My localhost runs on port 8080.
username-root
hostname=localhost
password=no
global privileges=ALL
PRIVILEGES Grant= yes
You have confused the Webserver with the MySQL Server. Your web server is running on port 8080, not your MySQL Server. The MySQL server runs on port 3306 (by default) so your web application needs to connect to it on that port.
Change your mysqli connect string to:
$conn = new mysqli('localhost','root', '', 'votesystem', '3306');

Warning: mysqli_connect(): (HY000/2002): Connection refused in

Cannot figure out why I am getting this error?
Warning: mysqli_connect(): (HY000/2002): Connection refused in
Here the code:
$con = mysqli_connect('localhost:3306', '********', '********');
mysqli_select_db ($con, "id9873966_search") or die mysqli_error($con));
If you're using the standard port 3306 you should just be able to write
$con = mysqli_connect("localhost", "username", "password", "id9873966_search");
Assuming you actually have a db named id9873966_search
Additionally, if you're on Windows PC you can open CMD as admin and run
netstat -a -b
This will generate a list of services listening on what ports so you can verify you are in fact using port 3306 on localhost. You can also open "Services" in Windows and ensure that your DB is installed and listening.
It may also be necessary to add a firewall rule on you machine.

How to get the socket for MySQLi to Oracle DB connection?

I am new with web development. I have difficulty in connecting to an oracle DB. This code was patterned from the Oracle documentation.
I am sure with the connection details except the socket.Is the socket on default? or How do I get the socket detail from the Oracle DB interface?
$host="site.com";
$port=1404;
$socket="/tmp/mysql.sock";
$user="admin";
$password="admin123";
$dbname="admin_table";
/* create a connection object which is not connected */
$conn = new mysqli();
$conn -> init();
/* set connection options */
$conn -> options (MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=0");
$conn -> options (MYSQLI_OPT_CONNECT_TIMEOUT, 200);
/* connect to MySQL server */
$conn -> real_connect ($host, $user, $password, $dbname, $port, $socket)
or die ('Could not connect to the database server : ' . $conn -> error . '\n');
I also encounter these errors:
Warning: mysqli::real_connect() [mysqli.real-connect]: MySQL server has gone away in C:\wamp\www\Lot_Verification\pages\DB_Connect.php on line 19
Warning: mysqli::real_connect() [mysqli.real-connect]: Error while reading greeting packet. PID=6572 in C:\wamp\www\Lot_Verification\pages\DB_Connect.php on line 19
Warning: mysqli::real_connect() [mysqli.real-connect]: (HY000/2006): MySQL server has gone away in C:\wamp\www\Lot_Verification\pages\DB_Connect.php on line 19
Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\Lot_Verification\pages\DB_Connect.php on line 20

Connection issue with mysqli

$db= mysqli_connect('localhost', "root", "root");
if(!$db) die("Error connecting to MySQL database.");
mysqli_select_db("onlineform", $db);
As I try to connect to the database like shown above, I am getting the following error:
Warning: mysqli_connect(): [2002] No such file or directory (trying to connect
via unix:///var/mysql/mysql.sock) in - on line 3 Warning: mysqli_connect():
(HY000/2002): No such file or directory in - on line 3 Error connecting
to MySQL database.
It's my first time using mysqli, I thought it would be a big improvement over mysql. I checked with MAMP if it's enabled and it is.
Any suggestions?
Check if your socket is correct. If not, override the default socket. I guess you have to try something like this in MAMP:
$link = mysql_connect(
':/Applications/MAMP/tmp/mysql/mysql.sock',
'root',
'root'
);

need help connecting to RDS from local and EC2

I am trying to connect to RDS from my localhost and ec2 server.
I can connect fine with MySQL Workbench 5.2 CE but i cant seem to connect with PHP.
They are in the same zone and security group.
$dbName = "*******-****.***************.**-****-*.rds.amazonaws.com:3306";
$dbTable = "myTable";
$dbUser = "myUser";
$dbPass = "*********";
define("HOST", $dbName);
define("DBUSER", $dbUser);
define("PASS", $dbPass);
define("DB", $dbTable);
$conn = new mysqli(HOST, DBUSER, PASS, DB) or die();
these are the errors
Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: php_network_getaddresses: getaddrinfo failed: No such host is known.
Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://*******-****.***************.**-****-*.rds.amazonaws.com:3306)
Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known.
the endpoint works fine as i said with the client, not on browser.
but what does this error mean, and how would i start debugging this?
Have you checked the security group for your amazon ec2 in your amazon admin console. please check you have opened the port for mysql (i.e 3306)

Categories