Does include_once for MySQL connection in 2 separate <?php ?> tags will connect only once?
In this case I use:
<?php include_once 'connect.php'; # connect with MySQL database # some PHP code ?> <!-- some HTML code --> <?php # here PHP code wants to use MySQL connection opened before ?>
Should I even include_once in 2nd PHP tag?
You don't need to re-include a file if it's within the same request/page.
Also, using include_once will prevent you from including files that have already been included.
You're free to use again variables and connection previously included by your connect.php
The include_once statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include statement, with the only difference being that if the code from a file has already been included, it will not be included again. As the name suggests, it will be included just once.
So if connect.php is included once it will not be included again
<?php include(a.php) //it will include a.php include(b.php) //it will include b.php include(a.php) //it will include a.php again ?> <?php include_once(a.php) //it will include a.php include_once(b.php) //it will include b.php include_once(a.php) //does nothing ?>