0

I'm trying to connect to MySQL database but, I'm getting an error.

Code:

<?php
    ini_set('mysql.connection_timeout',300);
    ini_set('default_socket_timeout',300);
    define('DB_SERVER', 'localhost:8080');
    define('DB_USERNAME', 'root');
    define('DB_PASSWORD', '');
    define('DB_DATABASE', 'sib');
    $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

Which gives me the error:

Warning: mysqli_connect(): MySQL server has gone away in C:\xampp\htdocs\SIB\connect.php on line 9

Warning: mysqli_connect(): Error while reading greeting packet. PID=10696 in C:\xampp\htdocs\SIB\connect.php on line 9

Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\xampp\htdocs\SIB\connect.php on line 9

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\SIB\connect.php on line 9

2
  • From the warnings it sounds like you have not set up MySQL server correctly or you do not have it running. You might have skipped some steps in the xampp setup -- time to read the instructions? Commented Jun 4, 2019 at 22:53
  • 1
    It sounds like you are trying to send large chunk of data to MySQL. Is that really all of your code? Or maybe the port specified is incorrect? Commented Jun 4, 2019 at 22:55

1 Answer 1

1

The first thing is that your port must be specified as a separate parameter to mysqi_connect, not together with host. - The second thing is that You are not connecting to MySQL, but to Apache server. If you didn't change MySQL port just use define('DB_SERVER', 'localhost'); in place of define('DB_SERVER', 'localhost:8080');

<?php 
     ini_set('mysql.connection_timeout',300);
     ini_set('default_socket_timeout',300);
     define('DB_SERVER', 'localhost');
     define('DB_USERNAME', 'root');
     define('DB_PASSWORD', '');
     define('DB_DATABASE', 'sib');
     $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE,3306); 

as per php.net/manual/en/mysqli.quickstart.connections.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.