All pastes #21877 Raw Edit

Miscellany

public text v1 · immutable
#21877 ·published 2005-09-01 21:08 UTC
rendered paste body
 /**
        * Load a list of database objects
        * @param string The field name of a primary key
        * @return array If <var>key</var> is empty as sequential list of returned records.
        * If <var>key</var> is not empty then the returned array is indexed by the value
        * the database key.  Returns <var>null</var> if the query fails.
        */
        function loadObjectList( $key='' ) {
                if (!($cur = $this->query())) {
                        return null;
                }
                $array = array();
                while ($row = mysql_fetch_object( $cur )) {
                        if ($key) {
                                $array[$row->$key] = $row;
                        } else {
                                $array[] = $row;
                        }
                }
                mysql_free_result( $cur );
                return $array;
        }
        /**
        * @return The first row of the query.
        */
        function loadRow() {
                if (!($cur = $this->query())) {
                        return null;
                }
                $ret = null;
                if ($row = mysql_fetch_row( $cur )) {
                        $ret = $row;
                }
                mysql_free_result( $cur );
                return $ret;
        }