note 34351 deleted from ref.odbc by sniper

From: Date: Tue, 04 Nov 2003 00:38:35 +0000
Subject: note 34351 deleted from ref.odbc by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-59768@lists.php.net to get a copy of this message
Note Submitter: mike (at) NOSPAM blamires.co.uk ---- This code is from a php5.0.0(b1) abstract class I use as a baseclass for all my pages it holds the connection throughout the lifetime of the instance. It is fairly generic (and messy/not thouroughly tested yet!). It returns either a 3D Array or an Array depending on the result which you can manipulate from your other objects classes etc. It gets round al the odbc_num_rows problems many drivers eem to suffer. I hope this helps people, comments welcome. Many thanks. Mike final function __construct() { # not to be overidden!! # connection initialised during the lifetime of the object instance $this->$connection = odbc_connect("owl", "", ""); } final function __destruct() { # not to be overidden!! # close $connection resource upon estruction of the object instance (the page handles this). # mop up database connections stopping memory leaks and zombie threads. Hopefully! odbc_close($this->$connection); unset($this->$connection); } protected function dbQuery($query, $select) { # $query = SQL Statement # $select = boolean (true if SQL is SELECT statement, false if SQL is not SELECT statement) # performs SQL query on $connection # the result is multiple lines). It is then up to the initaiting script to use the # data passed back in the array $result = odbc_exec($this->$connection, $query); # Query database $s=0; while(odbc_fetch_row($result)) { $s++; } if ($select) { if ($s > 1) { # check no of rows returned action to correct array type. $final = array(); $i = 0; while($i<=$s) { $j=1; while($j<=odbc_num_fields($result)) { $final[$i][$j] = odbc_result($result, $j); # 3D Array $j++; } $i++; } } else { $final = odbc_fetch_row($result); # Array } } return $final; }

« previous php.notes (#59768) next »