PHP

OpenBase PHP

The PHP archive contains the files necessary to add OpenBase support to PHP.  The module source has been recently modified in January 2009 to support MacOS X leopard, 64 bit architechtures and OpenBase. 

OpenBase provides a complete PHP 5.2.8 installation package at http://www.openbase.com/download for all MacOS X architectures. If you need sources, please contact OpenBase directly.

videoicon3.png Video: Using PHP with OpenBase

OpenBase PHP5 Tutorial

The OpenBase PHP interface was designed to mimic the OpenBase C API closely. However, because of the way PHP is often used we have changed some of the return values and have created new methods to accommodate PHP programmers. 

The php_examples directory includes three examples. They are described as follows:

movies.php
movies2.php
queryeditor.php

movies.php

Connects to the movies database and provides an example search mechanism. Look up your favorite movie by title, rating, category or studio name. movies.php joins two tables together and displays results.

The movies.php example demonstrates the use of ob_nextRowWithResult where the column result values are copied directly into your php program variables.

Code Example:

while(ob_nextRowWithResult($connection, &$category, &$title, &$rated, &$name)) {
    print("$category $title $rated $name");
}

movies2.php

movies2.php is the same as movies.php except that it also demonstrates retrieving and displaying BLOBs using the ob_retrieveBinary command.

Code example:

while(ob_nextRowWithResult($connection, &$category, &$title, &$rated, &$summaryId) ) {
    $summary = ob_retrieveBinary($connection, $summaryId); 
    print("$category $title $rated $summary");
}

queryeditor.php

queryeditor.php uses the Company example database. It allows users to enter any query they want into a text field and have the php program execute it. Since the number of rows and columns are not known, it uses ob_resultColumnCount and ob_resultColumnValue to display the rows and columns in the result.

Code example:

$numberOfColumn = ob_resultColumnCount($connection); ...
while(ob_nextRowWithResult($connection)) { print("");
    for($i = 0; $i $numberOfColumn; $i++) {
        $param = ob_resultColumnValue($connection, $i); print(" $param ");
    }
    print(" ");
}

Commands to Connect/Access OpenBase Database

The following commands can be used within PHP to connect and access the OpenBase database.

OpenBase PHP5 Reference

The OpenBase PHP interface was designed to mimic the OpenBase C API closely. However, because of the way PHP is often used we have changed some of the return values and in some cases we have created new methods to accommodate PHP programmers.

ob_connect(database_name_param, hostname_param, user_param, password_param)
connect to the specified Openbase database

ON SUCCESS returns an OpenBaseConnection
ON FAILURE returns an error string

ob_pconnect(database_name_param, hostname_param, user_param, password_param, id_param)
connect to the specified Openbase database

ON SUCCESS returns an OpenBase connection
ON FAILURE returns an error string

ob_disconnect(OpenBaseConnection)
disconnect from the Openbase database connected to with OpenBaseConnection

ob_makecommand(OpenBaseConnection , theCommandParameter)
creates a command buffer on the connection for execution

NO RETURN VALUE

ob_executecommand(OpenBaseConnection)
executes the commands

ON SUCCESS returns an true
ON FAILURE returns an false

ob_nextrowwithresult(OpenBaseConnection, …)
gets the next row from the result set into variables

takes a varying list of parameters by reference

if there is a next row returns 0
if there is no next row returns 1

ob_nextrowwitharray(OpenBaseConnection, array)
gets the next row from the result set into an array

if there is a next row returns 0
if there is no next row returns 1

ob_nextrowwithassocarray(OpenBaseConnection, assocArray)
gets the next row from the result set into an associative array

if there is a next row returns 0
if there is no next row returns 1

ob_rowsaffected(OpenBaseConnection)
get the number of rows affected by the last command

ob_resultcolumnname(OpenBaseConnection, theColumnNumberParameter)
get the column name

ob_resultcolumnvalue(OpenBaseConnection, theColumnNumberParameter)
get the column value

ob_resultcolumncount(OpenBaseConnection)
get the number of columns in the results of the last command

ob_begintransaction(OpenBaseConnection)
begin a transaction

ob_bufferhascommands(OpenBaseConnection)
determine if the connection command buffer has commands to execute

ob_clearcommands(OpenBaseConnection)
clear the connections command buffer

ob_commandbuffer(OpenBaseConnection)
return the contents of the connections command buffer

ob_committransaction(OpenBaseConnection)
commit the transaction

ob_databasename(OpenBaseConnection)
get the name of the database connected to in the connection

ob_abortfetch(OpenBaseConnection)
abort fetching records

ob_hostname(OpenBaseConnection)
get the name of the host connec ted to in the connection

ob_iscolumnnull(OpenBaseConnection, theColumnNumberParameter)
determine if a column is null

ob_loginname(OpenBaseConnection)
get the login name used in the connection

ob_password(OpenBaseConnection)
get the password used in the connection

ob_resultcolumntype(OpenBaseConnection , theColumnNumberParameter)
determine the type of a column

ob_resultreturned(OpenBaseConnection)
returns true when there is a result set.

ob_resulttablename(OpenBaseConnection , theColumnNumberParameter)
get the name of the table the column in the result set came from

ob_rollbacktransaction(OpenBaseConnection)
roll back the last transaction on the connection

ob_servermessage(OpenBaseConnection)
get the server message

ob_uniquerowidfortable( OpenBaseConnection , theTableName)
get a unique row id for a new row for the table named

ob_uniquerowidfortablecolumn( OpenBaseConnection , theTableName, theColumnName)
get a unique row id for a new row for the table and column named

ob_insertblob( OpenBaseConnection , theBlobString)
insert a blob value and return a blob id

ob_insertclob( OpenBaseConnection, theBlobString)
insert a clob value and return a blob id

ob_retrieveblob( OpenBaseConnection, theBlobId)
retrieve the blob identified by blobID

ob_retrieveclob( OpenBaseConnection, theBlobId)
retrieve the clob identified by blobID

ob_setclientencoding( OpenBaseConnection, clientEncodingParameter)
set the clients encoding

ob_clientencoding( OpenBaseConnection)
read what client encoding is being used

ob_databaseencoding( OpenBaseConnection)
read the data encoding of the server.

Building OpenBase PHP Sources

This instructions will help you compile PHP 5.2.8 with the source to the OpenBase PHP Module. It is based on the official PHP 5.2.8 distribution from http://www.php.net

Installation Requirements

Building PHP requires the latest developer tools from Apple, available on CD or from the Apple Developer Connection site in the developer section of apple.com.  We recommend that you run Mac OS X (or X Server) 10.5 or later. 

Building PHP 5.2.8 for OpenBase on Leopard (MacOS X 10.5)

It may be desirable to build OpenBase support directly in to PHP.  PLEASE READ THROUGH ALL INSTRUCTIONS BEFORE PERFORMING STEPS.

Follow these instructions: 

1. Download PHP 5.2.8 from http://www.php.net
2. Copy the 'openbase_module' source directory to php-5.2.8/ext/
3. Open Terminal to issue the following commands:

$ sudo cp /usr/libexec/apache2/libphp5.so /usr/libexec/apache2/libphp5.so.apple
$ cd /path-to-php/php-5.2.8
$ mv configure configure.bck
$ ./buildconf --force

CFLAGS="-arch x86_64 -g -Os -pipe -no-cpp-precomp -arch x86_64" CCFLAGS="-arch x86_64 -g -Os -pipe " CXXFLAGS="-arch x86_64 -g -Os -pipe" LDFLAGS="-arch x86_64" ./configure '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs2=/usr/sbin/apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql-sock=/var/mysql' '--with-mysqli=/usr/bin/mysql_config' '--with-mysql=/usr' '--with-openssl' '--with-xmlrpc' '--with-xsl=/usr' '--without-pear' '--enable-openbase_module' 

$ ./configure --prefix=/usr/local/php5 --with-apxs2 --enable-openbase_module
$ make clean
$ make
$ sudo make install

4. Edit the apache2 config file to load the module. Add or uncomment mime type lines below (between the lines): 

--------------------------------------------------------
LoadModule php5_module   /usr/libexec/apache2/libphp5.so
AddModule mod_php5.c 
AddType application/x-httpd-php .php 
AddType application/x-httpd-php-source .phps 
--------------------------------------------------------

5. Restart the Apache web server.

sudo apachectl restart

Configuration Options

It may be necessary to have additional configuration or compiler flags depending on the architecture and required modules. These are just a few examples:

Leopard 10.5 - Apache 2 - 32 bit

CFLAGS="-arch i386 -g -Os -pipe -no-cpp-precomp -arch i386" CCFLAGS="-arch i386 -g -Os -pipe " CXXFLAGS="-arch i386 -g -Os -pipe" LDFLAGS="-arch i386" ./configure '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs2=/usr/sbin/apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql-sock=/var/mysql' '--with-mysqli=/usr/bin/mysql_config' '--with-mysql=/usr' '--with-openssl' '--with-xmlrpc' '--with-xsl=/usr' '--without-pear' '--enable-openbase_module'

Leopard 10.5 - Apache 2 - 64 bit

CFLAGS="-arch x86_64 -g -Os -pipe -no-cpp-precomp -arch x86_64" CCFLAGS="-arch x86_64 -g -Os -pipe " CXXFLAGS="-arch x86_64 -g -Os -pipe" LDFLAGS="-arch x86_64" ./configure '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs2=/usr/sbin/apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql-sock=/var/mysql' '--with-mysqli=/usr/bin/mysql_config' '--with-mysql=/usr' '--with-openssl' '--with-xmlrpc' '--with-xsl=/usr' '--without-pear' '--enable-openbase_module'

Leopard 10.5 - Apache 2 - PPC

CFLAGS="-arch ppc -g -Os -pipe -no-cpp-precomp -arch ppc" CCFLAGS="-arch ppc -g -Os -pipe " CXXFLAGS="-arch ppc -g -Os -pipe" LDFLAGS="-arch ppc" ./configure '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs2=/usr/sbin/apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql-sock=/var/mysql' '--with-mysqli=/usr/bin/mysql_config' '--with-mysql=/usr' '--with-openssl' '--with-xmlrpc' '--with-xsl=/usr' '--without-pear' '--enable-openbase_module'
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License