DRAFT PHP3 API for Interbase
Table of Contents
ibase_errmsg
ibase_errmsg -- returns error message of last InterBase call
Description:
string ibase_errmsg();
Returns: last InterBase error or false if no errors
example:
$result = @ibase_query("select FOO from BAR");
if(ibase_errmsg() != 0){
echo "Oops! Can't get FOO from bar.";
echo "error: " . ibase_errmsg();
}
--------------------------
ibase_connect
Description:
int ibase_connect(string database [, string username] [, string password] [, string charset]);
Returns: An InterBase link identifier on success, or false on
error.
ibase_connect() establishes a connection to a InterBase server.
The database argument has to be a valid path to database file.
Username and password can be specified in <php.ini> with
ibase.default_user and ibase.default_password.
In case a second call is made to ibase_connect() with the same
arguments, no new link will be established, but instead, the link
identifier of the already opened link will be returned.
The link to the server will be closed as soon as the execution of the
script ends, unless it's closed earlier by explicitly calling
<ibase_close()>.
See also <ibase_pconnect()>, <ibase_close()>.
-------------------------------------
ibase_pconnect
ibase_pconnect -- open persistent InterBase server connection
Description:
int ibase_pconnect(string database [, string username] [, string password] [, string charset]);
Returns: An InterBase link identifier on success, or false on
error.
ibase_pconnect() acts very much like <ibase_connect()> with two
major differences.
First, when connecting, the function would first try to find a
(persistent) link that's already open with the same host, username
and password. If one is found, an identifier for it will be returned
instead of opening a new connection.
Second, the connection to the SQL server will not be closed when
the execution of the script ends. Instead, the link will remain open for
future use (<ibase_close()> will not close links established by
<ibase_pconnect()>).
This type of links is therefore called 'persistent'.
-------------------------------------
ibase_close
ibase_close -- close InterBase connection
Description
int ibase_close([int link_identifier]);
Returns: true on success, false on error.
ibase_close() closes the link to a InterBase database that's
associated with the specified link identifier. If the link identifier isn't
specified, the last opened link is assumed.
Default transaction on link commited, other transactions
rolled back.
See also: <ibase_connect()>, <ibase_pconnect()>, <Transactions>.
-------------------------------------
ibase_trans
ibase_trans -- starts InterBase transaction
Description
int ibase_trans([int trans_args] [, int link]);
Returns: An InterBase transaction identifier on success, or false on
error.
ibase_trans start transaction.
If trans_args ommited, InterBase defaults
(READ WRITE WAIT SNAPSHOT) assumed.
trans_args one of IBASE_READ,IBASE_COMMITED,IBASE_CONSISTENCY,
IBASE_NOWAIT or summ IBASE_READ+IBASE_NOWAIT etc...
If link omitted, last open link assumed.
For transaction with InterBase defaults on any link
specify IBASE_DEFAULT as trans_args, or 0.
$trans_id = ibase_trans(IBASE_DEFAULT, $link_3);
or
$trans_id = ibase_trans(0, $link_3);
Note: IBASE_DEFAULT not mean 'default transaction' but
READ WRITE WAIT SNAPSHOT transaction arguments.
See also: <ibase_commit()>, <ibase_rollback()>, <Transactions>.
-------------------------------------
ibase_commit
ibase_commit -- commit InterBase transaction
Description
int ibase_commit([int trans_id | link_id]);
Returns: true on success, false on error
ibase_commit commit InterBase transaction.
If no link_id/trans_id specified, last open link assumed.
If link_id specified, default transaction on link commited.
See also: <ibase_trans()>, <ibase_rollback()>, <Transactions>.
-------------------------------------
ibase_rollback
ibase_rollback -- rollback InterBase transaction.
Description
int ibase_rollback([int trans_id | int link_id]);
Returns: true on success, false on error.
ibase_rollback rollback InterBase transaction.
If no link_id/trans_id specified, last open link assumed.
If link_id specified, default transaction on link assumed.
See also: <ibase_trans()>, <ibase_commit()>, <Transactions>.
-------------------------------------
ibase_query
ibase_query -- send InterBase query.
Description
int ibase_query([int link_id | trans_id, ] string query [, bind args ...]);
Returns: An InterBase result identifier or true if
no select query on success, or false on error.
ibase_query sends a query to the currently active database on
the server that's associated with the specified link identifier. If the
link identifier isn't specified, the last opened link is assumed.
If no link_id/trans_id specified, default transaction on last open link
assumed.
ibase_query support InaterBase placeholders '?' . When placeholders
specified, you must provide same numer of binded arguments to ibase_query.
When result not longer need free it with ibase_free_result.
example:
$foo = 10;
$result = ibase_query("SELECT FOO FROM BAR WHERE FOO BETWEEN 1 AND ?",
$foo); ... /* work with ibase_fetch... */
ibase_free_result($result);
See also: <ibase_free_result()>, <ibase_prepare()>, <ibase_execute()>.
---------------------
ibase_prepare
ibase_prepare -- parse InterBase query.
Description
int ibase_prepare([int link_id | trans_id, ] string query);
Returns: An InterBase query identifier on success, or false on
error.
ibase_prepare parse query and prepare it to execute. Use
when you need more querys with some tables and columns and
diffirent arguments. Time consuming parsing and optimizing
will done only in ibase_prepare.
If no link_id/trans_id specified, default transaction on last open link
assumed.
When query not longer need free it with ibase_free_query.
example:
/* prepare query */
$query_id = ibase_prepare("SELECT FOO FROM BAR WHERE FOOO = ?");
for($i = 0; $i < 10; $i++){
/* execute prepared query */
$result = ibase_execute($query_id, $i);
while($row = ibase_fetch_object($result))
echo $row->FOO;
ibase_free_result($result);
}
/* free query */
ibase_free_query($query_id);
See also: <ibase_free_query()>, <ibase_execute()>.
---------------------
ibase_execute
ibase_execute -- execute prepared InterBase query.
Description
int ibase_execute(int query_id [, bind_args ... ]);
Returns: An InterBase result identifier or true if
no select query on success, or false on error.
ibase_execute execute prepared query. ibase_execute support
InaterBase placeholders '?' . When placeholders
specified (in ibase_prepare call), you must provide same
number of binded arguments to ibase_query.
When result not longer need free it with ibase_free_result.
example:
/* prepare query */
$query_id = ibase_prepare("SELECT FOO FROM BAR WHERE FOOO = ?");
for($i = 0; $i < 10; $i++){
/* execute prepared query */
$result = ibase_execute($query_id, $i);
while($row = ibase_fetch_object($result))
echo $row->FOO;
ibase_free_result($result);
}
/* free query */
ibase_free_query($query_id);
See also: <ibase_prepare()>, <ibase_free_query()>.
---------------------
ibase_fetch_row
ibase_fetch_row -- fetch row as enumerated array
Returns: An array that corresponds to the fetched row, or false if
there are no more rows.
Description
array ibase_fetch_row(int result [,int flag]);
ibase_fetch_row fetches one row of data from the result
associated with the specified result identifier. The row is returned as
an array. Each result column is stored in an array offset, starting at
offset 0.
Subsequent call to ibase_fetch_row would return the next row in
the result set, or false if there are no more rows.
DATE columns returns as string (format set with <ibase_timefmt()> )
or as timestamp if flag IBASE_TIMESTAMP specified.
BLOB columns returns as blob_string_id or as string if flag IBASE_TEXT
specified.
example:
$set = ibase_query("SELECT V_INTEGER, V_DATE, V_BLOB, V_ARRAY FROM
FOO");
while($row = ibase_fetch_row($set, IBASE_TEXT+IBASE_TIMESTAMP)){
echo
$row[0], /* integer */
date("l dS of F Y h:i:s A", $row[1]), /* date in user
format */ $row[2], /* all blob in string */
$row[3][1], /* array element 1 */
$row[3][2], /* array element 2 */
$row[3][3], /* array element 3 */
;
}
See also: <ibase_fetch_object()>, <ibase_timefmt()>, <BLOBs>.
-------------------
ibase_fetch_object
ibase_fetch_object -- fetch row as object
Description
array ibase_fetch_oject(int result [,int flag]) ;
Returns: An object with properties that correspond to the fetched
row, or false if there are no more rows.
ibase_fetch_object fetches one row of data from the result
associated with the specified result identifier. The row is returned as
an array. Each result column is stored in object properties named
as selected columns.
Subsequent call to ibase_fetch_object would return the next row in
the result set, or false if there are no more rows.
DATE columns returns as string (format set with <ibase_timefmt()> )
or as timestamp if IBASE_TIMESTAMP specified.
BLOB columns returns as blob_string_id or as string if IBASE_TEXT
specified.
example:
$set = ibase_query("SELECT V_INTEGER AS I, V_DATE, V_BLOB, V_ARRAY
FROM FOO");
while($row = ibase_fetch_object($set, IBASE_TEXT+IBASE_TIMESTAMP)){
echo
$row->I, /* aliased v_integer */
date("l dS of F Y h:i:s A", $row->V_DATE), /*date in user
format */ $row[2], /* all blob in string */
$row->V_ARRAY[1], /* array element 1 */
$row->V_ARRAY[2], /* array element 2 */
$row->V_ARRAY[3], /* array element 3 */
;
}
See also: <ibase_fetch_row()>, <ibase_timefmt()>, <BLOBs>.
------------------
ibase_free_result
ibase_free_result -- free InterBase result resource.
Description
int ibase_free_result(int result);;
Returns true on success, false on error.
ibase_free_result() free result created with ibase_query or
ibase_execute call. Empty or 'false' result not caused error.
ibase_free_result() only needs to be called if you are worried about
using too much memory while your script is running. All result
memory will automatically be freed when the script, you may call
ibase_free_result() with the result identifier as an argument and the
associated result memory will be freed.
See also: <ibase_query()>, <ibase_execute()>.
------------------
ibase_free_query
ibase_free_query -- free InterBase query resource.
Description
int ibase_free_query(int query_id);
Returns true on success, false on error.
ibase_free_query() free query resource created with
ibase_prepare call.
See also: <ibase_prepare()>, <ibase_execute()>.
------------------
ibase_timefmt
ibase_timefmt -- set DATE input/output format.
Description
int ibase_timefmt(string format);
Returns true on success, false on error.
ibase_timefmt set DATE output format for ibase_fetch_row,
ibase_fetch_object and input format for ibase_query, ibase_execute.
For format description see <function.date.html>.
Worked only on platform where strftime function supported.
Default format is "%m/%d/%Y %H:%M:%S".
See also: <date()>.
----------------
ibase_num_fields
ibase_num_fields -- return number columns in result.
Description
int ibase_num_fields(int result);;
Returns number of fields in a result set.
See also: <ibase_field_info()>.
---------------
ibase_field_info
ibase_field_info -- return column description.
Description
object ibase_field_info(int result, int field_number);
Returns object with column description.
Object properties:
name -- column name
alias -- column alias, different from name
if clause 'AS' in select specified
relation -- column relation
length -- column length
type -- one of TEXT, VARYING, SHORT, LONG, FLOAT,
DOUBLE, D_FLOAT, DATE, BLOB, ARRAY, QUAD.
example:
$set = ibase_query("SELECT V_INTEGER AS I, V_DATE, V_BLOB, V_ARRAY
FROM FOO"); $coln = ibase_num_fields($set);
for($i = 0; $i < $coln; $i++){
$col_info = ibase_field_info($set, $i);
echo "name: $col_info->name\n";
echo "alias: $col_info->alias\n";
echo "relation: $col_info->relation\n";
echo "length: $col_info->length\n";
echo "type: $col_info->type\n";
}
See also: <ibase_num_fields()>.
---------------
ibase_blob_create
ibase_blob_create -- create new BLOB
Description
int ibase_blob_create([int link | trans]);
Returns: blob_id or false on error.
ibase_blob_create create new BLOB in database for filling with data.
example:
/* create blob */
$blob_id = ibase_blob_create();
/* fill with data */
ibase_blob_add($blob_id, "string1");
ibase_blob_add($blob_id, "string2");
ibase_blob_add($blob_id, "string3");
ibase_blob_add($blob_id, "last string");
/* close and get $blob_id_str for inserting into table */
$blob_id_str = ibase_blob_close($blob_id);
/* finally insert blob into table */
ibase_query("INSERT INTO BLOB_TABLE (BLOB_NUM, BLOB_1) VALUES (1, ?)",
$blob_id_str);
Note: Be careful with transaction stuff here. Create and insert into
table must be in one transaction context.
See also <ibase_blob_add()>, <ibase_blob_close()>, <ibase_blob_cancel()>,
<BLOBs>.
---------------
ibase_blob_open
ibase_blob_open -- open BLOB for read.
Description
int ibase_blob_open(string blob_id_str);
Retruns: blob_id or false on error.
ibase_blob_open open BLOB for read data. blob_id_str retrived
from database with select.
example:
$set = ibase_query("SELECT V_BLOB FROM FOO WHERE ID = 999");
$row = ibase_fetch_object($set);
$blob_id = ibase_blob_open($row->V_BLOB);
$string = ibase_blob_get($blob_id);
echo $string;
ibase_blob_close($blob_id);
ibase_free_result($set);
See also <ibase_blob_close()>, <ibase_blob_get()>, <BLOBs>.
----------------
ibase_blob_add
ibase_blob_add -- add data into new BLOB
Description
int ibase_blob_add(int blob_id, string data);
ibase_blob_add add data into new BLOB created with ibase_blob_create.
example: see <ibase_blob_create()>.
Note: Don't use this function for create BLOB from file. See
<ibase_blob_import()>.
See also <ibase_blob_create()>, <ibase_blob_close()>,
<ibase_blob_cancel()>, <BLOBs>.
----------------
ibase_blob_get
ibase_blob_get -- get BLOB data.
Description
string ibase_blob_get(int blob_id, int len);
Returns string with BLOB data or false if there are no more data.
ibase_blob_get() reads at most len bytes from a BLOB and
returns it as a string. blob_id specifies a BLOB open with
<ibase_blob_open()> and len specifies the maximum allowable size
of the BLOB segment.
Note: Don't use this function just for output blob to browser. See
<ibase_blob_echo()>.
example:
$set = ibase_query("SELECT V_BLOB FROM FOO WHERE ID = 999");
$row = ibase_fetch_object($set);
$blob_id = ibase_blob_open($row->V_BLOB);
while($string = ibase_blob_get($blob_id, 1024)){
/* .. some editing work with $string here... */
echo $string;
}
ibase_blob_close($blob_id);
ibase_free_result($set);
See also <ibase_blob_open()>, <ibase_blob_close()>, <ibase_blob_echo()>,
<BLOBs>.
----------------
ibase_blob_close
ibase_blob_close -- close new BLOB.
Description
int ibase_blob_close(int blob_id);
Returns blob_id_str suitable for inserting into table or false on
error.
ibase_blob_close close blob created with ibase_blob_create and
filled with ibase_blob_add.
example: see <ibase_blob_create()>.
See also <ibase_blob_close()>, <ibase_blob_add()>, <ibase_blob_cancel()>,
<BLOBs>.
----------------
ibase_blob_cancel
ibase_blob_cancel -- cancel new BLOB.
Description
int ibase_blob_cancel(int blob_id);
Returns true on success, or false on error.
ibase_blob_cancel discard blob created with ibase_blob_create and
filled with ibase_blob_add.
example:
$blob_id = ibase_blob_create();
/* fill with data */
$fp = fopen("tenchi.rm","r");
while($piece = fread($fp, 1024)){
if(strstr($piece, "dont putLOB_NUM, BLOB_1) VALUES (1, ?)",
$blob_id_str);
See also---------------------------
ibase_blob_info
ibase_blob_info -- get BLOB description.
Description
object ibase_blob_info(string blob_id_str);
Returns object with BLOB description.
blob_id_str created with ibase_fetch_row() or ibase_fetch_object().
Object properties:
length -- total BLOB length, in bytes
numseg -- number BLOB segments
maxseg -- maximum length of BLOB segment
stream -- 1 - BLOB is stream
isnull -- BLOB is null
example:
$set = ibase_query("SELECT V$set);
$blob_info = ibase_blob_info($row->B);
echo "length: $blob_info->length\n";
echo "numseg: $blob_info->numseg\n";
echo "maxseg: $blob_info->maxseg\n";
echo "stream: $blob_info->stream\n";
echo "isnull: $blob_info->isnull\n";
----------------------------
ibase_blob_echo
ibase_blob_echo -- output BLOB contents to the browser.
Descriprue on success, false on error.
ibase_blob_echo() ;
reads all BLOB and passes it straight through
to the browser after sending all pending headers. Mainly intended
for sending binary data like images or sound.
example:
$set = ibase_query("SELECT V_BLOB AS B FROM FOO");
$row = ibase_fetch_object($set);
ibase_blob_echo($row[0])
;
------------------
ibase_blob_import
ibase_blob_import -- create new BLOB from file
Description
string ibase_blob_import([int link_id | trans_id, ] int fd);;
Returns blob_id_str, or false on error.
If no link_id/trans_id specified, default transaction on last open link
assumed.
ibase_blob_import created new BLOB, import file data,
closed BLOB and return blob_id_str suitable for insert
into table. en("zeiram.mpeg","r");
$blob_id_str = ibase_blob_import($fd);
ibase_query("INSERT INTO BLOB_TABLE (BLOB_NUM, BLOB_1) VALUES (1, ?)",
$blob_id_str);
See also <ibons
-------------------------
Default transaction.
It used when encounters one of ibase_query, ibase_prepare,
ibase_blob_create, ibase_blob_import without specifing
link/transaction argument.
Default transaction on default link selected, if transaction
not open, it opens with InterBase defaults
READ WRITE WAIT ISOLATION LEVEL SNAPSHOT.
To start default transaction, but change its parameters
<ibase_t
When script ends or user call <ibase_close()> default
transaction commited.
example:
/* open default transaction in ibase_query() */
$result = ibase_query("SELECT FOO FROM BAR");
/* open second transaction */
$trans_2 = ibase_trans();
/* commit default */
ibase_commit();
/* here no default transaction, $trans_2 _NOT_ used as default */
/* thus, in next ibase_query opens new default transaction */
ibase_query("DELETE FROM BAR");
...
/* and when script ends, default transaction commited */
2. Other transactansaction already active.
You can open up to 10 transactions on link.
When script ends or user call <ibase_close()> this transactions
rollback. For saving changes you must call <ibase_commit()>.
3. Link identifier and transaction identifier.
Transaction identifier contain link identifier.
For ibase_query, ibase_prepare, ibase_blob_create, ibase_blob_import,
ibase_commit, ibase_rollback you can specify link or transacton identifier.
If link specified, default transaction on link used.
example:
/* before execution in table test5 one row */
$tr_1 = ibase_trans(); /* this default transaction also */
$tr_2 = ibase_trans(IBASE_READ);
$tr_3 = ibase_trans(IBASE_READ+IBASE_COMMITED);
/* default transaction context */
/* one row here */
$res = ibase_query("select * from test5");
ibase_free_result($res);
/* insert in default (first) transaction context... */
ibase_query("insert into test5 (i) values (3)");
/* specify transaction context */
ibase_query($tr_1, "insert into test5 (i) values (4)");
/* test. three rows return here. */
$res = ibase_query("select * from test5");
/* specify transaction context. three rows again. */
$res = ibase_query($tr_1, "select * from test5");
/* commit default. specify $tr_1 not necessary. */
ibase_commit($tr_1);
/* one row in second transaction context */
$res = ibase_query($tr_2, "select * from test5");
/* three rows in third transaction context */
$res = ibase_query($tr_3, "select * from test5");
...
ibase_close();
Limit to 10 transaction on link defined in php3_interbase.h.
If you need other value, change IBASE_TRANS_ON_LINK before
php compilation.
--------------------------
BLOBs note
Two types of BLOB identifier used:
1. blob_id_str stored in database. Returns by ibase_fetch_row,
ibase_fetch_object, ibase_blob_close, ibase_blob_import.
Can be inserted into table.
2. blob_id created by ibase_blob_open, ibase_blob_create.
Can be used for partial read/write BLOB data. Not suitable
for insert into database table.
BLOB segment size 4096 bytes defined in php3_interbase.h.
If you think that other value can improve performance,
change IBASE_BLOB_SEG before php compilation.
--------------------------
php.ini
InterBase Configuration Directives
ibase.allow_persistent boolean
Whether to allow persistent InterBase connections.
ibase.max_persistent integer
The maximum number of persistent InterBase connections per
process.
ibase.max_links integer
The maximum number of InterBase connections per process,
including persistent connections.
ibase.default_user
User name to use if none is specified in <ibase_connect()> or
<ibase_pconnect()>.
ibase.default_password
Password to use if none is specified in <ibase_connect()> or
<ibase_pconnect()>.
ibase.timeformat
DATE columns format. For format description see <date()>.
--------------------------
Constants used
in <ibase_trans()>:
PHP3_IBASE_DEFAULT 0
PHP3_IBASE_READ 4
PHP3_IBASE_COMMITED 8
PHP3_IBASE_CONSISTENCY 16
PHP3_IBASE_NOWAIT 32
in <ibase_fetch_row()>, <ibase_fetch_object()>:
PHP3_IBASE_TEXT 1
PHP3_IBASE_TIMESTAMP 2
---------------------------