I use at the beginning of the page:

session_start(); if(!isset($_SESSION['db'])) $_SESSION['db'] = mysqli_connect('localhost', 'user', 'password', 'mydb'); $db = $_SESSION['db']; 

Further on page work with requests goes normally. I run a script through ajax, in which at the top of the page:

 session_start(); $db = (object) $_SESSION['db']; 

And then the work with the requests does not go, errors in the requests, as if there is no disconnection, what is the error?

  • one
    You are doing something completely wrong. In each new process (and this is your new process), you must initialize the connection to the database if you want to access it. And the old connection pointer won't help you. - Visman
  • Perhaps it is better to write values ​​for the connection to the variable (host, login, password, database), and then create a new connection in the code? - Ep1demic
  • Visman, you are right, now I understand - Yuri
  • Ep1demic, yes, this option will do. - Yuri

0