Subject | RE: [firebird-php] how connections are handled ? |
---|---|
Author | Nigel Weeks |
Post date | 2005-06-28T03:41:41Z |
> prepare SPIf you only call the SP once, you can let PHP prepare it for you. Just call
> 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 ?
>
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:
<?php
// 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)){
$rows++;
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
loop).
* Then freeing results will save memory use creeping up and using swap
space.
* ----------
*/
?>