PHP Classes

Oracle wrapper: Oracle database access wrapper class

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2007-07-26 (8 years ago) RSS 2.0 feedStarStarStarStar 61%Total: 2,924 All time: 1,203 This week: 1,107Up
Version License Categories  
oraclewrapper 1.0Freely DistributableDatabases
Description Author  

This class is meant to provide an API to wrap around Oracle database access functions. The API is compatible with the one provided by the Mysql.lib.php wrapper.

Picture of Tarmo Protsin
Name: Tarmo Protsin <contact>
Classes: 1 package by
Country: Estonia Estonia
Age: 36
All time rank: 10194 in Estonia Estonia
Week rank: 1624 Down5 in Estonia Estonia Down

Readme for Oracle.lib.php (Oracle database access wrapper class)

This class is meant to provide an API to wrap around Oracle database access functions. 
The API is compatible with the one provided by the Mysql.lib.php wrapper.

Also see 'Oracle.test.php' for example scripts.

1) Include the class file in your script:


2) Create an instance of Oracle (make an object):

	$dbc = new Oracle();

3) Connect to Oracle database, call method connect with connection parameters:
	$dbc->connect($Sid, $Username, $Password);
	You can also give connection parameters into class constructor and so skip step 3:
		$dbc = new Oracle($carr); // where $carr = array('sid', 'username', 'password');

4) Set query string:

	$sql = "SELECT * FROM USERS"; // this is an example!

5) Execute query:

	$dbc->query($sql); // returns FALSE on error, TRUE on success
	On Error you can get Oracle error message from string $dbc->get_error_string():
	The $dbc->Error is Array, so you have to format it yourself: 
		$dbc->Error = Array(
			'code' => 'the error code',
			'message' => 'error message',
			'offset' => 'error offset in query',
			'sqltext' => 'the query string'

		if ( !$dbc->query($sql) )
			print "Error ocurred: " . $dbc->get_error_string();

6) Get query result rows:
	$result_arr = array();
	while ( $dbc->next_record() ) 
		$result_arr[] = $dbc->Record; // the whole row
		$result_arr[] => $dbc->f('fieldname'); // one field value from current row
		$result_arr[] => $dbc->Record['fieldname']; // same as above
	You can use handy help function 'build_results()',
	that gets the whole result into array (skiping step 5):
		$result_arr = $dbc->build_results($sql);

7) Happy?

Public methods in the Oracle class:

//  Class constructor, sets connection parameters (in array $arrp), if given
	Oracle($arrp = null)

// connects to database with given parameters (session id, username, password)
// parameters are not needed when parameters are given in class contructor
	connect($Sid = '', $Username = '', $Password = '') // returns FALSE on error, TRUE on success

// Disconnects from database
	disconnect() // returns FALSE on error

// Executes query, returns FALSE on error, TRUE on success


// For compability with Mysql.lib.php, not doing anything

	last_insert_id() // in this case returns 0 (zero)
		Here is how you can get last inserted id in Oracle:
		(you have to have sequence named USERS_SEQ for table USERS) 
			$sql = "INSERT INTO USERS(FIRSTNAME, LASTNAME, USERNAME[, ...]) VALUES ( 'blaa', 'blaa', 'blaa'[, ...])";
			if ( !$dbc->query($sql) )
				return 0; // query failed
			if ( $dbc->query($sql) && $dbc->next_record() )
				return $dbc->f('NEW_ID'); // return squence's current value (last inserted id for table USERS)

// Executes query, inserts query result rows into array
	build_results($query); // returns created array

// Gets next record (row) from query result


// Seeks to (result) row nr $r


// Returns given field's ($name) value


// Returns the Error Array as string

Tarmo Protsin <>
  Files folder image Files  
File Role Description
Plain text file Oracle.lib.php Class Oracle wrapper for PHP
Accessible without login Plain text file Oracle.test.php Example Test file for Oracle wrapper
Accessible without login Plain text file readme_Oracle_wrapper.txt Doc. Readme for Oracle wrapper class

 Version Control Unique User Downloads Download Rankings  
 0%Total:2,924All time:1,203
 This week:0This week:1,107Up
 User Ratings  
 All time