Tuesday, April 11, 2006

Php Firebird (ehm Interbase) functions ...

A post on Devshed forums showed that the php manual did not have any detailed info about ibase_service_attach and some other Interbase/Firebird functions, of course the question has been answered in the forums and the user promised to add a note on the official docs, anyway here is a small example of use of that specific function:
// get server version and implementation strings
if (($service = ibase_service_attach('localhost', 'sysdba', 'masterkey')) != FALSE) {
$server_info = ibase_server_info($service, IBASE_SVC_SERVER_VERSION)
. ' / '
. ibase_server_info($service, IBASE_SVC_IMPLEMENTATION);
else {
$ib_error = ibase_errmsg();
echo $server_info;


Which echoes something like

WI-T2.0.0.12484 Firebird 2.0 Release Candidate 1 / Firebird/x86/Windows NT

A more useful example would be using the whole thing to create a new user, you'll have to attach to server as a user with appropriate privileges (like SYSDBA) and then issue an:

ibase_add_user($service, 'pippo', 'pp')

where $service is the resorce got from the ibase_service_attach, 'pippo' is the username and 'pp' is the password

Sample code taken and adapted from the ibWebAdmin source code.

No comments: