I use ubuntu 18 server by google cloud instance
I installed xammp, status is:
sudo /opt/lampp/lampp status
Version: XAMPP for Linux 5.6.15-1
Apache is running.
MySQL is running.
ProFTPD is running.
I send request http post by my angular application from localhost to this server.
It's not working.
this server application is PHP and mySql
when i browser the url server, i get error:
Warning: mysqli::mysqli(): (HY000/2002): Connection timed out in
/opt/lampp/htdocs/dashboard/models/sql.php on line 12 Connection
failed: Connection timed out
sql.php (line 12):
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
when I run those from localhost by xammp. it's working.
Thank!
Related
<?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');
after the start apache server, i could not access PHPMyAdmin. when i try to access i get an error and auto-stop MySQL server.
- mysqli_real_connect(): (HY000/2002): No connection could be made
because the target machine actively refused it.
- Connection for controluser as defined in your configuration failed.
mysqli_real_connect(): (HY000/2002): No connection could be made
because the target machine actively refused it.
- phpMyAdmin tried to connect to the MySQL server, and the server
rejected the connection..
how can i solve this error
Add below line under config.inc.php
$cfg['Servers'][$i]['port'] = 8111;
If you are on Windows os and the above solution does not work, just check if your mysql is running with "netstat -ano" command, if the services are not running just try starting the mysql service.
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.
I'm trying to run a PHP Script that contains a MySQL connection, when I run the command I get the following error in the terminal:
'Warning: mysqli::__construct(): (HY000/2002): Connection refused'
Even with PDO, I get the error:
'Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in ...'
I'm running the script on Mac OS X, and I have MAMP as APACHE/MySQL local server.
The command that I use for running the script is:
'php main.php'
and the content of the 'main.php' file with PDO is:
$db = new PDO('mysql:host=localhost;dbname=test',root,root);
with mysqli connector:
$db = new mysqli("localhost", "test", "root", "root");
I tried with '127.0.0.1' instead of 'localhost' and I get the same errors in both cases.
First of all, using localhost as a domain name is not supported in PHP. It will not be resolved as 127.0.0.1.
Second, even using 127.0.0.1 might not work in servers with multiple interfaces or with special routing rules. Run mysqlcheck --help and take the IP address shown at the bottom in the "host" field. For example:
port 3306
host 192.168.1.23
Use the IP and port that MySQL recognizes:
$db = new mysqli("192.168.1.23:3306", "test", "root", "root");
My goal is to run php on glassfish server. I installed Quercus and deployed it as an application within glassfish under (C:\glassfish4\glassfish\domains\domain1\applications\Quercus).
Now I try to connect to mysql. The mysql server is running and connection is verified through command (mysql -u root -p).
next test.php is created:
<?php
$servername="localhost";
$username="root";
$password="whatever";
$conn = new mysqli($servername, $username, $password);
if (!$conn) {
die("Failed : " . mysqli.connect_error());
}
echo "Connection Successful!";
?>
Running test.php gives the following message:
Warning: A link to the server could not be established.
url=jdbc:mysql://localhost/?
jdbcCompliantTruncation=false&characterSetResults=ISO885_1&characterEncoding=ISO8859_1&userServerPrepStmts=true
driver=com.mysql.jdbc.Driver com.caucho.quercus.QuercusModuleException:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Connection Successful!
From the message, it is probable that the mysql jdbc driver is not installed.
I added the driver to C:\glassfish4\glassfish\domains\domain1\lib\mysql-connector-java-8.0.11\mysql-connectior-java-8.0.11.jar. I am not sure how to add it from glassfish admin console. It is not shown under jdbc>connection pool.
2nd EDIT (based on comments):
The jar files are moved into ...\domain1\lib and ...\glassfish\lib as well. A full system restart was done.
To add a connection pool, I Followed the instructions on the following link:
https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-glassfish-config.html
Then I get the following error message:
HTTP Status 500 - Internal Server Error:
type Exception report
message Internal Server Error
description The server encountered an internal error that prevented it from fulfilling this request.
exception java.lang.IllegalStateException: getoutputStream() has already been called for this response.
...