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?

Answers


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

For example

<?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
?>

Need Your Help

How to create an Expression<Func<dynamic, dynamic>> - Or is it a bug?

c# dynamic .net-4.0 lambda expression-trees

During my work with expression trees for a few days now, I came across something that I find difficult to understand; hopefully someone will be able so shed some light here.

Why does fail for SKNode members in iOS8?

ios8 sprite-kit nsset sknode

Two objects are added to an NSSet, but when I check membership, I can't find one of them.