I can't connect to my server. Here are the mistakes it gives me:
Warning: mysqli::__construct(): MySQL server has gone away in
C:\xampp\htdocs\www\PHP-Project\logic\db_connection.php on line 3
Warning: mysqli::__construct(): Error while reading greeting packet.
PID=8632 in C:\xampp\htdocs\www\PHP-Project\logic\db_connection.php on
line 3
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone
away in C:\xampp\htdocs\www\PHP-Project\logic\db_connection.php on
line 3
Fatal error: Maximum execution time of 30 seconds exceeded in
C:\xampp\htdocs\www\PHP-Project\logic\db_connection.php on line 3
This is my connection file:
define("HOST", "localhost:81");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_NAME", "bulitfactory_person_cv");
$db_connection = new mysqli(HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($db_connection->connect_error) {
die("Connection failed. ".$db_connection->connect_error);
}
Please, help me!
try it to increase max_allowed_packet and restart the server
Add log_warnings=2 within [mysqld]section to your .ini/.cfg file, shutdown restart mysql and you should have maximum connection failure information in your error.log.
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');
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
I'm facing this problem since yesterday evening. I have been now over 6 hours on Google, trying to figure out what the solution could be.
I have tried this, setting the timeout on all php.ini files to 300 or unlimited, I have tried setting the buffer of MySQL higher, tried to restart both Apache and MySQL server, ...
Problem: What I'm trying to do, where the error occurs, is to execute a SOAP-command (command is correct) $this -> soap -> executeCommand(new SoapParam($command, 'command'));, which results in:
"Could not connect to host" --> if I set define('DB_HOST', '127.0.0.1'); or
Problem 2:
//Warning: mysqli::mysqli() [function.mysqli-mysqli]: (HY000/2003): Can't connect to MySQL server on 'blacktempel.dyndns-home.com' (10060) in C:\Users\NAME\Desktop\Server_09122014\Apache\_Server\htdocs\SOAPRegistration.php on line 109
//Warning: mysqli::close() [function.mysqli-close]: Couldn't fetch mysqli in C:\Users\NAME\Desktop\Server_09122014\Apache\_Server\htdocs\SOAPRegistration.php on line 154
$this -> db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); //Line 109
$this -> db -> close(); //Line 154
"Database connection failed: Can't connect to MySQL server on 'blacktempel.dyndns-home.com' (10060)" --> if I set define('DB_HOST', 'blacktempel.dyndns-home.com');.
My firewall is not the problem, I have checked this multiple times.
My hosts file contains this:
# 127.0.0.1 localhost
# ::1 localhost
MyExternalIp blacktempel.dyndns-home.com
SOAP:
define('SOAP_IP', '127.0.0.1');
define('SOAP_PORT', '7878');
MySQL is running on port 3306 and listening. My other defines, such as DB_USER, DB_PASS, are correct.
Q: Why won't it work ? What could be wrong ? Is there anything I could possibly have missed ?
Fixed the issue.
The SOAP problem was caused by a setting in the config file of the program accessed by SOAP.
$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'
);
I'm having some problems while trying to connect a .php with mysql.
here's the connection.php code
<?php
$db_host =$_POST['localhost'];
$db_user =$_POST['root'];
$db_password = "";
$db_name = "prtcl";
?>
and this is the page where I actually use the connection
<?
include("connection.php");
?>
...
<?php
$db = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name, $db);
if (!$db)
{
die('Could not connect: ' . mysql_error());
}
mysql_close($db);
?>
<body>
...
that's what I get when I try to load it ( line 29 is this one:
$db = mysql_connect($db_host,
$db_user, $db_password);
)
Notice: Undefined variable: db_host in
C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Notice: Undefined variable: db_user in
C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Notice: Undefined variable:
db_password in C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Warning: mysql_connect()
[function.mysql-connect]: [2002] A
connection attempt failed because the
connected party did not (trying to
connect via tcp://localhost:3306) in
C:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Warning: mysql_connect()
[function.mysql-connect]: 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:\Program Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
Fatal error: Maximum execution time of
30 seconds exceeded in C:\Program
Files
(x86)\EasyPHP-5.3.2\www\prtcl\index.php on line 29
as you can see I'm using EasyPHP and, since this very code used to work before (with a different db, while using manually configured apache/mysql), may be that the reason? Other infos: I made the db using phpmyadmin and I have win7
thank you
Don't ever take your db credentials from $_POST without validation. This is such a terrible idea and this is what's causing your errors, as these keys are not being defined in $_POST, but they could be and the results could be disastrous!
try putting this in connect.php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "prtcl";
$db = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name, $db);
if(!$db) {
die('Could not connect: ' . mysql_error());
}
then in your other pages use:
require_once("path/to/connect.php");
// ... whatever else you do on this page...
I would find out why the $db_host variable is not getting defined. That might be a problem with your form input. Check to see that the name of that input field really is 'localhost'. Also, as Mark Baker mentioned above, you really want to do some input cleansing to guard against sql injection attacks. Plus, is there any reason you can't hardcode the db host info into a configuration file?