Subject RE: [firebird-php] how connections are handled ?
Author Nigel Weeks
> prepare SP
> execute SP
> fetch rows
> free result
> commit
> disconnect
> Is this is the correct way of handing connection? Do I
> have to connect and disconnect each time when the user press
> the submit button? Can I open a db connection for an entire
> session? ie, connect to db when the user login and disconnect
> when the user logout or when a timeout occurs?
> Please shed some light on this queries ?

If you only call the SP once, you can let PHP prepare it for you. Just call
it via ibase_query.

Preparation of a query(wether executing an SP, or pulling records), only
yields benefits if it's called more than once in a transaction.

Disconnects happen at the end of a PHP script, whether you ask for it or not
- PHP does not support pooling or re-connection to transactions over
script executions.

A quick script to show you:


// Connect to the database
$conn = ibase_connect("server:/path/to/database.fdb","sysdba","masterkey");

// Write a query
$sql = "select 'Hi There!' from rdb\$database";

// Run the query
$rec = ibase_query($sql);

// Get the outputs(if any)
$rows = 0;
while($row = ibase_fetch_row($rec)){
echo "A row was returned! Column '0' contains: ".$row[0]."<br>";

// How many rows did we get?
echo "Rows Returned: ".$rows."<br>";

* We could do an ibase_close(), and an ibase_free_result(),
* but it's gonna happen anyway...
* This will matter if your script doesn't end (command-line app with a
* Then freeing results will save memory use creeping up and using swap
* ----------