1
When using a PHP application with Firebird database we use the methods ibase_connect()
to open the connection to the database and ibase_close()
to close that connection. If the connection is opened and is not closed with the use of the last command, when finishing the execution of the SQL command the connection is terminated.
And the databases have different performances when opening the connection to the database, according to what I was told Firebird is one of the databases in which the connection takes to open, so I would like to propose a solution to this in our projects.
Can it be saved in session and is it a way that can be considered? Example:
Database.php:
<?php
session_start();
function OpenConnection(){
if (empty($_SESSION['connection'])){
$host = 'localhost:/path/to/your.gdb';
$dbh = ibase_connect($host, $username, $password);
$_SESSION['connection'] = $dbh;
}
}
?>
File1.php:
<?php
include_once('Database.php');
OpenConnection();
$conn = $_SESSION['connection'];
// Resto das operações
?>
Questions:
- The above idea is considered a good practice?
- Is there another way to do it? How?
- Is there any (s) article(s) explaining how Facebook can maintain a connection for each user? You can mention in your reply?