Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

note 34351 added to ref.odbc

0 views
Skip to first unread message

mi...@rack1.php.net

unread,
Jul 24, 2003, 10:21:51 AM7/24/03
to blamire...@rack1.php.net
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

sni...@php.net

unread,
Nov 3, 2003, 7:38:35 PM11/3/03
to php-...@lists.php.net
Note Submitter: mike (at) NOSPAM blamires.co.uk

----

0 new messages