Skip to main content

Posts

Showing posts from December, 2021

How to use mysqli_close() if SQL query being executed in a function and function called on some other page ?

  <?php   //DB connection // new mysqli(host, user, password, database name); $ DBConnection = mysqli_connect ( " localhost:3308 " , " bit " , " bitbyte " , " bit_yt " ); //Check connection if ( mysqli_connect_errno ()){     echo " Failed to connect to MySQL: ". mysqli_connect_error ();     exit (); } function testFunction1 (){   global $ DBConnection ;   $ sql = mysqli_query ($ DBConnection , " SELECT * FROM students " );   print_r ( mysqli_fetch_all ($ sql , MYSQLI_ASSOC ));   mysqli_close ($ DBConnection ); } function testFunction2 ( $ DBConnection ){   $ sql = mysqli_query ($ DBConnection , " SELECT * FROM students " );   print_r ( mysqli_fetch_all ($ sql , MYSQLI_ASSOC ));   mysqli_close ($ DBConnection ); } testFunction1 (); //use any of one testFunction2 ( $ DBConnection );