I wrote a simple PHP code to connect to the MySQL server as below
<?php
$username = "root";
$password = "Kepwd";
$hostname = "localhost:81";
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
but this generates the following errors. I found some topics regarding this issue in google and Stack Overflow. but those don't help me.
( ! ) Warning: mysqli_connect(): MySQL server has gone away in C:\wamp\www\SSDConsultingNew\inc\test.php on line 8
Call Stack
# Time Memory Function Location
1 0.0014 240936 {main}( ) ..\test.php:0
2 0.0014 241528 mysqli_connect ( ) ..\test.php:8
( ! ) Warning: mysqli_connect(): Error while reading greeting packet. PID=10612 in C:\wamp\www\SSDConsultingNew\inc\test.php on line 8
Call Stack
# Time Memory Function Location
1 0.0014 240936 {main}( ) ..\test.php:0
2 0.0014 241528 mysqli_connect ( ) ..\test.php:8
( ! ) Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\wamp\www\SSDConsultingNew\inc\test.php on line 8
Call Stack
# Time Memory Function Location
1 0.0014 240936 {main}( ) ..\test.php:0
2 0.0014 241528 mysqli_connect ( ) ..\test.php:8
Unable to connect to MySQL
The error is here:
$hostname = "localhost:81";
You are not connecting to MySQL, but to Apache server. If you didn't change MySQL port just use
$hostname = "localhost";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With