MYSQL and PHPMYADMIN cant connect via php - php

Ive set up phpmyadmin and mySql on my windows server but when i try to connect via php i get this error :
Warning: mysqli::mysqli(): MySQL server has gone away in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Warning: mysqli::mysqli(): Error while reading greeting packet. PID=15852 in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Warning: mysqli::mysqli(): (HY000/2006): MySQL server has gone away in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Catchable fatal error: Object of class mysqli could not be converted to string in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 14
I know by default mySql only allows local connections but following tutorials online they are all saying to uncomment a line in a "my.ini" file. All i have in my sql folder is a my-default.ini with the following :
How can i open this up to connections from an external php script?

Try adding this to your php.ini:
mysqli.reconnect = 1

Related

Warning: mysqli::__construct(): (HY000/2002): No such file or directory in [duplicate]

This question already has answers here:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
(17 answers)
Closed 2 years ago.
I'm totally stuck having spent a couple of days trying to figure this out...
I have set up an Apache web server (version 2.4.34) on my Mac OS running Mojave (10.14.3) and have installed the current version of MySQL Community Server (8.0.15). Both running perfectly as I can determine (from command line). I have PHP 7.1.23 installed. When I create a .php file with the following code and put it in my Sites directory and then in Safari go to http://localhost/~dave/hello.php I get this error:
"Warning: mysqli::__construct(): (HY000/2002): No such file or
directory in /Users/dave/Sites/hello.php on line 7 Connection failed:
No such file or directory".
Code in hello.php:
<?php
$servername = "localhost";
$username = "dave";
$password = "*****";
//Create connection
$conn = new mysqli($servername, $username, $password);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
I have tried everything I can think of, including those suggestions in the other two similar posts (this one: My database user exists, but I still get an (HY000/2002): No such file or directory and this one: PHP Warning: mysqli::__construct(): (HY000/2002): No such file or directory (Debian GNU/Linux 9)), and I cannot connect to MySQl with php. In particular, I checked with the php info page and the socket for mysqli is given as var/mysql/mysql.sock. In the relevant table in mysql the value for socket is given as /tmp/mysql.sock. I tried changing the php.ini.default file by adding each of these sockets (in place of the empty value) and neither worked (still generates the same error). I thought that the 2002 MySQL socket error might be the problem, so I made a symlink by doing this:
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
but all that did was generate a new error:
Warning: mysqli::__construct(): The server requested authentication
method unknown to the client [caching_sha2_password] in
/Users/dave/Sites/hello.php on line 7
Warning: mysqli::__construct(): (HY000/2054): The server requested
authentication method unknown to the client in
/Users/dave/Sites/hello.php on line 7 Connection failed: The server
requested authentication method unknown to the client
So I removed the symlink...and returned to the original error.
I also tried replacing "localhost" with the IP address 127.0.0.1 as well as "localhost:3306" as other question threads have suggested. Nothing worked here either.
Please help, I am new to this kind of use of the computer/web design and I'm out of obvious (googleable/understandable) options.
Use 127.0.0.1 instead of localhost.
I got some help from some local tech guys in my area and it turns out that fixing the socket error was the first step, like I tried to do above. I eventually did it this way, using the solution by noun:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
The second error message was then generated (same one as in my question, here again):
mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in /Users/dave/Sites/hello.php on line 7
Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /Users/dave/Sites/hello.php on line 7
This was fixed by the SQL-based solution (June 9 2018 answer) to this question:
php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
This SQL statement was simply run in MySQL from the terminal. After restarting the Apache server I reloaded the .php file in Safari and this resulted in a successful mysqli connection to MySQL with PHP. I also tried a PDO connection and this also worked.

php can not connect to mysql after reboot server

Software:
PHP 7.3
MySQL Workbench 8.0
This is my PHP code:
try {
$link = mysqli_connect($DB_SERVER,$DB_USERNAME, $DB_PASSWORD,$DB_NAME,3306);
} catch (Exception $e){
throw new Exception("Can't execute command. ERROR: ".$e);
}
This is the error:
Warning: mysqli_connect(): PHP was built without openssl extension, can't send password encrypted in login.php on line 11
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'XXXXX_admin'#'localhost' (using password: YES) in C:\inetpub\wwwroot\ on line 11
PHP Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\inetpub\wwwroot\ on line 24
PHP Fatal error: Uncaught Exception: ERROR: Failed to connect to in C:\inetpub\wwwroot:24 Stack trace: #0 {main} thrown in C:\inetpub\wwwroot\ on line 24
Now the magic, when I login in to mysql workbench with the same user and password everything works fine. I have access to tables and other things. When I login in with my PHP application everything works also.
So my problem is everytime my server reboots I have to login in with MySQL Workbench, to get it working again. What am I missing?
You need to do verify few of the steps:
All necessary extensions are enabled like mysqli, openssl etc
Port is available
MySQLi is connecting at 3306 Port
Rest could be your username and password issue
Let us know once you will be verifying all above steps.
What you need to do is enable the openssl extension for php.
Open your php.ini file and search for the line:
;extension=php_openssl.dll
You need to uncomment it by removing the semicolon in front of it, leaving you with this:
extension=php_openssl.dll

Failed to connect to MySQL: Can't connect to MySQL server on 'sql306.juichost.ml' (113 "No route to host")

I have looked everywhere for a fix, but could only find ones for localhost or private sites.
I keep getting this error:
Failed to connect to MySQL: Can't connect to MySQL server on 'sql306.juichost.ml' (113 "No route to host")
The website is Here. I am using this website host for mysql, but hostmonster for the actual hosting.
I have tried ping sql306.juichost.ml and gotten this:
ping: sendto: Host is down
Request timeout for icmp_seq 876.
I have no idea what to that means though.
In the error log I see:
[01-Nov-2017 09:52:56 UTC] PHP Warning: include(): Failed opening 'inc/database.php' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in /home/aussieug/public_html/ppyazi/license/login.php on line 2
And
[01-Nov-2017 09:52:56 UTC] PHP Notice: Undefined variable: con in /home/aussieug/public_html/ppyazi/license/login.php on line 14
Line 2:
include 'inc/database.php';
Line 14:
$checksettings = mysqli_query($con, "SELECT * FROM `settings` LIMIT 1") or die(mysqli_error($con));
Please keep in mind that I am very new to terminal and php so I need detailed answers.

Unknown MySQL server host

After a php verison change i have the following error
Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL server host
'clouddb.myhost.gr:3306' (2) in
/var/www/vhosts/mywebside.gr/httpdocs/system/library/db/mysqli.php on
line 7Warning: DB\MySQLi::__construct(): Couldn't fetch mysqli in
/var/www/vhosts/mywebside.gr/httpdocs/system/library/db/mysqli.php on
line 10Warning: DB\MySQLi::__construct(): Couldn't fetch mysqli in
/var/www/vhosts/mywebside.gr/httpdocs/system/library/db/mysqli.php on
line 10 .
And i cant understand what is the problem
You might be passing the clouddb.myhost.gr:3306 all together, on the mysqlcli, the port have its own parameter:
mysql:host=clouddb.myhost.gr;port=3306;
Related question:
SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)

PHP timeout during simple connection to MySQL - on win2k8 64bit IIS 7 / FastCGI php - new install

I installed PHP/FastCGI and Mysql on w2k8 64bit IIS7.
PHPinfo() loads fine, and MySQL extension is properly installed. PHP displays echo commands.
MySQL also works fine through the MySQL Command Line Client. I can create DBs, tables and users.
However MySQL does not respond and the PHP script times out when simply connecting with mysql_connect("localhost","user goes here","pass goes here");
I miss win2k3.
Any ideas?
PHP 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:\inetpub\wwwroot\test.php on line 9 PHP 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:\inetpub\wwwroot\test.php on line 9 PHP Fatal error: Maximum execution time of 60 seconds exceeded in C:\inetpub\wwwroot\test.php on line 12
Can you try 127.0.0.1 instead of localhost?
Seems to be a right-out bug.

Categories