note 34351 added to ref.odbc

From: Date: Thu, 24 Jul 2003 14:21:51 +0000
Subject: note 34351 added to ref.odbc
Groups: php.notes 
Request: Send a blank email to php-notes+get-52574@lists.php.net to get a copy of this message
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; } ---- Manual Page -- http://www.php.net/manual/en/ref.odbc.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34351 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34351&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34351&report=yes

« previous php.notes (#52574) next »