Пример #1
0
 /**
  * Devuelve la cantidad de filas de un resultado de query
  * 
  * @access public
  * @param (object) result set
  * @return (int) cantidad de filas en el resulta set
  */
 function numero_filas($rs)
 {
     // Fix para odbc_num_rows que siempre devuelve -1 para MS Access
     $count = 0;
     while ($temp = odbc_fetch_into($rs, $counter)) {
         $count++;
     }
     // Reset cursor position
     odbc_fetch_row($rs, 0);
     return $count;
 }
Пример #2
0
 function FetchInto($result, $row, &$array)
 {
     if ($this->php_version >= 4002000) {
         return odbc_fetch_into($result, $array, $row);
     } elseif ($this->php_version >= 4000005) {
         return odbc_fetch_into($result, $row, $array);
     } else {
         eval("\$success=odbc_fetch_into(\$result,\$row,&\$array);");
         return $success;
     }
 }
Пример #3
0
function _fetch_array($bdid)
{
    global $ODBC_ID, $last_odbc_result;
    if (odbc_fetch_into($bdid, $res_odbc_row)) {
        foreach ($res_odbc_row as $k => $v) {
            $data_odbc_row[odbc_field_name($bdid, $k + 1)] = $v;
        }
        return $data_odbc_row;
    } else {
        return False;
    }
}
Пример #4
0
 /**
 	Thanks to ironhacker (ironhacker at users.sourceforge.net) for this!
 */
 function odbc_fetch_array_hack($result, $rownumber = -1)
 {
     $rs_assoc = array();
     if (PHP_VERSION > "4.1") {
         if ($rownumber < 0) {
             odbc_fetch_into($result, &$rs);
         } else {
             odbc_fetch_into($result, &$rs, $rownumber);
         }
     } else {
         odbc_fetch_into($result, $rownumber, &$rs);
     }
     foreach ($rs as $key => $value) {
         $rs_assoc[odbc_field_name($result, $key + 1)] = $value;
     }
     return $rs_assoc;
 }
Пример #5
0
 public function Find()
 {
     $conn = parent::GetConnection();
     $query = $this->SetupQuery(Query::FIND_STATISTICS);
     $result = odbc_exec($conn, $query);
     if (!$result) {
         return $this->HandleError();
     }
     $row = array();
     if (!odbc_fetch_into($result, $row)) {
         return $this->HandleError();
     }
     $this->idDailyTask = $row[0];
     $this->StatsClass = $row[1];
     $this->StartDate = $row[2];
     $this->EndDate = $row[3];
     return true;
 }
Пример #6
0
 function next_record()
 {
     $this->Record = array();
     $this->{$stat} = odbc_fetch_into($this->Query_ID, ++$this->Row, &$this->Record);
     if (!$this->{$stat}) {
         if ($this->Auto_Free) {
             odbc_free_result($this->Query_ID);
             $this->Query_ID = 0;
         }
     } else {
         // add to Record[<key>]
         $count = odbc_num_fields($this->Query_ID);
         for ($i = 1; $i <= $count; $i++) {
             $this->Record[strtolower(odbc_field_name($this->Query_ID, $i))] = $this->Record[$i - 1];
         }
     }
     return $this->Record;
 }
 public function Find()
 {
     if (!parent::Find()) {
         return false;
     }
     if ($this->StatsClass != "WalkingStats") {
         return false;
     }
     $conn = parent::GetConnection();
     $query = $this->SetupQuery(Query::FIND_WALKING_STATS);
     $result = odbc_exec($conn, $query);
     if (!$result) {
         return $this->HandleError();
     }
     $row = array();
     if (!odbc_fetch_into($result, $row)) {
         return $this->HandleError();
     }
     $this->Steps = $row[0];
     return true;
 }
 public function Find()
 {
     if (!parent::Find()) {
         return false;
     }
     if ($this->DailyTaskClass != "WalkingTask") {
         return false;
     }
     $conn = parent::GetConnection();
     $query = $this->SetupQuery(Query::FIND_WALKING_TASK);
     $result = odbc_exec($conn, $query);
     if (!$result) {
         return false;
     }
     $row = array();
     if (!odbc_fetch_into($result, $row)) {
         return false;
     }
     $this->Steps = $row[0];
     return true;
 }
 /**
  * Result - array
  *
  * subsititutes the odbc_fetch_array function when
  * not available (odbc_fetch_array requires unixODBC)
  *
  * @access	private
  * @return	array
  */
 function _odbc_fetch_array(&$odbc_result)
 {
     $rs = array();
     $rs_assoc = FALSE;
     if (odbc_fetch_into($odbc_result, $rs)) {
         $rs_assoc = array();
         foreach ($rs as $k => $v) {
             $field_name = odbc_field_name($odbc_result, $k + 1);
             $rs_assoc[$field_name] = $v;
         }
     }
     return $rs_assoc;
 }
Пример #10
0
var_dump($rval);
$val = odbc_result($rh, 1);
var_dump($val);
// fetch_array, next
echo "testing odbc_fetch_array, next\n";
$rval = odbc_fetch_array($rh);
var_dump($rval);
// fetch_array with row number
echo "testing odbc_fetch_array with row specified\n";
$rval = odbc_fetch_array($rh, 4);
var_dump($rval);
// fetch_object, next
echo "testing odbc_fetch_object, next\n";
$rval = odbc_fetch_object($rh);
var_dump($rval);
// fetch_object with row number
echo "testing odbc_fetch_object with row specified\n";
$rval = odbc_fetch_object($rh, 4);
var_dump($rval);
// fetch_into, next
$ar = array();
echo "testing odbc_fetch_into, next\n";
$rval = odbc_fetch_into($rh, $ar);
var_dump($rval);
var_dump($ar);
// fetch_into with row number
echo "testing odbc_fetch_into with row specified\n";
$rval = odbc_fetch_into($rh, $ar, 7);
var_dump($rval);
var_dump($ar);
echo odbc_close($r);
Пример #11
0
 /**
  * return a numeric indexed array.
  */
 function tryGet()
 {
     $succ = odbc_fetch_into($this->query, $row);
     if ($succ === false) {
         return false;
     } else {
         return $row;
     }
 }
Пример #12
0
function sql_fetch_row(&$res, $nr = 0)
{
    global $dbtype;
    switch ($dbtype) {
        case "MySQL":
            $row = mysql_fetch_row($res);
            return $row;
            break;
        case "mSQL":
            $row = msql_fetch_row($res);
            return $row;
            break;
        case "postgres":
        case "postgres_local":
            if ($res->get_total_rows() > $res->get_fetched_rows()) {
                $row = pg_fetch_row($res->get_result(), $res->get_fetched_rows());
                $res->increment_fetched_rows();
                return $row;
            } else {
                return false;
            }
            break;
        case "ODBC":
        case "ODBC_Adabas":
            $row = array();
            $cols = odbc_fetch_into($res, $nr, $row);
            return $row;
            break;
        case "Interbase":
            $row = ibase_fetch_row($res);
            return $row;
            break;
        case "Sybase":
            $row = sybase_fetch_row($res);
            return $row;
            break;
        default:
            break;
    }
}
Пример #13
0
 function _fetch()
 {
     $row = 0;
     $rez = odbc_fetch_into($this->_queryID, $row, $this->fields);
     if ($rez && $this->fetchMode == ADODB_FETCH_ASSOC) {
         $this->fields = $this->GetRowAssoc(false);
     }
     return $rez;
 }
function db_fetch_numarray(&$qhandle) {
	$row=array();
	odbc_fetch_into($qhandle,$row);
	return $row;
}
Пример #15
0
 function fetchInto($result, &$row, $fetchmode, $rownum = null)
 {
     $row = array();
     if ($rownum !== null) {
         $rownum++;
         // ODBC first row is 1
         if (version_compare(phpversion(), '4.2.0', 'ge')) {
             $cols = odbc_fetch_into($result, $row, $rownum);
         } else {
             $cols = odbc_fetch_into($result, $rownum, $row);
         }
     } else {
         $cols = odbc_fetch_into($result, $row);
     }
     if (!$cols) {
         /* XXX FIXME: doesn't work with unixODBC and easysoft
                          (get corrupted $errno values)
            if ($errno = odbc_error($this->connection)) {
                return $this->RaiseError($errno);
            }*/
         return null;
     }
     if ($fetchmode !== DB_FETCHMODE_ORDERED) {
         for ($i = 0; $i < count($row); $i++) {
             $colName = odbc_field_name($result, $i + 1);
             $a[$colName] = $row[$i];
         }
         if ($this->options['optimize'] == 'portability') {
             $a = array_change_key_case($a, CASE_LOWER);
         }
         $row = $a;
     }
     return DB_OK;
 }
Пример #16
0
 /**
  * ODBC Fetch object
  *
  * Emulates the native odbc_fetch_object() function when
  * it is not available.
  *
  * @param	resource	&$result
  * @param	int		$rownumber
  * @return	object
  */
 function odbc_fetch_object(&$result, $rownumber = 1)
 {
     $rs = array();
     if (!odbc_fetch_into($result, $rs, $rownumber)) {
         return FALSE;
     }
     $rs_object = new stdClass();
     foreach ($rs as $k => $v) {
         $field_name = odbc_field_name($result, $k + 1);
         $rs_object->{$field_name} = $v;
     }
     return $rs_object;
 }
Пример #17
0
 /**
  * Fetch a row and insert the data into an existing array.
  *
  * Formating of the array and the data therein are configurable.
  * See DB_result::fetchInto() for more information.
  *
  * @param resource $result    query result identifier
  * @param array    $arr       (reference) array where data from the row
  *                            should be placed
  * @param int      $fetchmode how the resulting array should be indexed
  * @param int      $rownum    the row number to fetch
  *
  * @return mixed DB_OK on success, null when end of result set is
  *               reached or on failure
  *
  * @see DB_result::fetchInto()
  * @access private
  */
 function fetchInto($result, &$arr, $fetchmode, $rownum = null)
 {
     $arr = array();
     if ($rownum !== null) {
         $rownum++;
         // ODBC first row is 1
         if (version_compare(phpversion(), '4.2.0', 'ge')) {
             $cols = @odbc_fetch_into($result, $arr, $rownum);
         } else {
             $cols = @odbc_fetch_into($result, $rownum, $arr);
         }
     } else {
         $cols = @odbc_fetch_into($result, $arr);
     }
     if (!$cols) {
         /* XXX FIXME: doesn't work with unixODBC and easysoft
                          (get corrupted $errno values)
            if ($errno = @odbc_error($this->connection)) {
                return $this->RaiseError($errno);
            }*/
         return null;
     }
     if ($fetchmode !== DB_FETCHMODE_ORDERED) {
         for ($i = 0; $i < count($arr); $i++) {
             $colName = @odbc_field_name($result, $i + 1);
             $a[$colName] = $arr[$i];
         }
         if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
             $a = array_change_key_case($a, CASE_LOWER);
         }
         $arr = $a;
     }
     if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
         $this->_rtrimArrayValues($arr);
     }
     if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
         $this->_convertNullArrayValuesToEmpty($arr);
     }
     return DB_OK;
 }
Пример #18
0
 /**
  * @see ResultSet::next()
  */
 public function next()
 {
     if ($this->limit > 0 && $this->cursorPos >= $this->limit) {
         $this->afterLast();
         return false;
     }
     $rowNum = $this->offset + $this->cursorPos + 1;
     $cols = @odbc_fetch_into($this->result->getHandle(), $this->fields, $rowNum);
     if ($cols === false) {
         $this->afterLast();
         return false;
     }
     $this->cursorPos++;
     if ($this->fetchmode == ResultSet::FETCHMODE_ASSOC) {
         for ($i = 0, $n = count($this->fields); $i < $n; $i++) {
             $colname = @odbc_field_name($this->result->getHandle(), $i + 1);
             $a[$colname] = $this->fields[$i];
         }
         $this->fields = $a;
         if (!$this->ignoreAssocCase) {
             $this->fields = array_change_key_case($this->fields, CASE_LOWER);
         }
     }
     return true;
 }
Пример #19
0
 function getid($seq_name)
 {
     $this->connect();
     $q = sprintf("select nextid from %s where seq_name = '%s'", $this->Seq_Table, $seq_name);
     $id = @odbc_do($this->Link_ID, $q);
     $res = array();
     $stat = odbc_fetch_into($id, &$res);
     if (!$stat) {
         if ($this->Auto_Free) {
             odbc_free_result($id);
             $id = 0;
         }
         $res = "";
     } else {
         // add to res[<key>]
         $count = odbc_num_fields($id);
         for ($i = 1; $i <= $count; $i++) {
             $res[strtolower(odbc_field_name($id, $i))] = $res[$i - 1];
         }
     }
     /* No current value, make one */
     if (!is_array($res)) {
         $currentid = 0;
     } else {
         $currentid = $res["nextid"];
     }
     return $currentid;
 }
 public function ListDailyTasks()
 {
     $this->Find();
     if ($this->UserClass != "Patient") {
         return array();
     }
     $conn = parent::GetConnection();
     $query = $this->SetupQuery(Query::LIST_DAILY_TASKS);
     $taskArray = array();
     $result = odbc_exec($conn, $query);
     if (!$result) {
         $this->HandleError();
         return array();
     }
     $row = array();
     while (odbc_fetch_into($result, $row)) {
         $className = $row[1] . "DAO";
         $taskArray[] = new $className();
         $i = count($taskArray) - 1;
         $taskArray[$i]->idDailyTask = $row[0];
         $taskArray[$i]->Find();
     }
     return $taskArray;
 }
Пример #21
0
 function fetchInto($result, &$row, $fetchmode, $rownum = null)
 {
     $row = array();
     if ($rownum !== null) {
         $rownum++;
         // ODBC first row is 1
         if (!function_exists('version_compare') || version_compare(phpversion(), "4.0.5", "lt")) {
             $cols = odbc_fetch_into($result, $rownum, &$row);
         } else {
             $cols = odbc_fetch_into($result, $rownum, $row);
         }
     } else {
         if (!function_exists('version_compare') || version_compare(phpversion(), "4.0.5", "lt")) {
             $cols = odbc_fetch_into($result, &$row);
         } else {
             $cols = odbc_fetch_into($result, $row);
         }
     }
     if (!$cols) {
         /* XXX FIXME: doesn't work with unixODBC and easysoft
                          (get corrupted $errno values)
            if ($errno = odbc_error($this->connection)) {
                return $this->RaiseError($errno);
            }*/
         return null;
     }
     if ($fetchmode !== DB_FETCHMODE_ORDERED) {
         for ($i = 0; $i < count($row); $i++) {
             $colName = odbc_field_name($result, $i + 1);
             $a[$colName] = $row[$i];
         }
         $row = $a;
     }
     return DB_OK;
 }
Пример #22
0
 function FetchArray($rsMain, &$result)
 {
     $rc = odbc_fetch_into($rsMain, $result);
     return $rc == false ? false : true;
 }
Пример #23
0
function make_results_table($result, $show_rowid, $table_name)
{
    if ($result === false) {
        ?>
		<div class="error_message">
			<?php 
        echo odbc_error() . ": " . odbc_errormsg();
        ?>
		</div>
<?php 
    } else {
        ?>
		<!-- TODO add edit/delete buttons for each row -->
		<!-- TODO field editing on click [?] -->
		<!-- TODO think about NULL -->
		<table class="results_table">
			<tr>
<?php 
        $fields_count = odbc_num_fields($result);
        $rowid_index = -1;
        for ($i = 1; $i <= $fields_count; ++$i) {
            $field_name = odbc_field_name($result, $i);
            if ($field_name == "ROWID" && !$show_rowid) {
                $rowid_index = $i - 1;
                continue;
            }
            echo "<th>" . $field_name . "</th>";
        }
        ?>
			</tr>
<?php 
        function treat_result($res)
        {
            if ($res == '') {
                return "&nbsp;";
            }
            return htmlspecialchars($res);
        }
        $res = array();
        $current_rowid = null;
        while (odbc_fetch_into($result, $res)) {
            $current_rowid = treat_result($res[$rowid_index]);
            echo "<tr id='row_" . $current_rowid . "'>";
            $controls = true;
            for ($i = 0; $i < $fields_count; ++$i) {
                if ($i == $rowid_index) {
                    continue;
                }
                echo "<td>" . treat_result($res[$i]);
                if ($controls && $table_name != null) {
                    $controls = false;
                    echo "<div class='row_control'>";
                    echo "<a class='button delete' href='javascript:delete_entry(\"" . $current_rowid . "\");'></a>";
                    echo "<a class='button edit' href='?tables&action=add_entry&target=" . $table_name . "&rowid=" . $current_rowid . "'></a>";
                    echo "</div>";
                }
                echo "</td>";
            }
            echo "</tr>";
        }
        ?>
		</table>
<?php 
    }
}
Пример #24
0
}
if (isset($dbuser)) {
    echo "Connecting to {$dsn} as {$dbuser}\n";
    $conn = odbc_connect($dsn, $dbuser, $dbpwd);
    if (!$conn) {
        ?>
<H2>Error connecting to database! Check DSN, username and password</H2>
<?php 
    } else {
        ?>
 - OK<p>
<?php 
        if (isset($display)) {
            if ($res = odbc_exec($conn, 'select id from php_test')) {
                echo "<H3>Images in database</H3>";
                while (odbc_fetch_into($res, &$imgs)) {
                    echo "{$imgs['0']} : <IMG SRC=\"odbc-display.php?id={$imgs['0']}&dbuser={$dbuser}&dsn={$dsn}&dbpwd={$dbpwd}\">\n<P>";
                }
            } else {
                echo "Couldn't execute query";
            }
            echo "\n</BODY>\n</HTML>";
            exit;
        }
        ?>
Dropping table "php_test"
<?php 
        Error_Reporting(0);
        $res = odbc_exec($conn, "drop table php_test");
        if ($res) {
            odbc_free_result($res);
Пример #25
0
 function _fetch()
 {
     if ($this->_has_stupid_odbc_fetch_api_change) {
         $rez = @odbc_fetch_into($this->_queryID, $this->fields);
     } else {
         $row = 0;
         $rez = @odbc_fetch_into($this->_queryID, $row, $this->fields);
     }
     if ($rez) {
         if ($this->fetchMode & ADODB_FETCH_ASSOC) {
             $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE);
         }
         return true;
     }
     $this->fields = false;
     return false;
 }
Пример #26
0
 function _fetch()
 {
     $row = 0;
     return odbc_fetch_into($this->_queryID, $row, $this->fields);
 }
Пример #27
0
/**
 * Retrieves a single row from the database and returns it as an array.
 *
 * <b>Note:</b> We don't use the more useful xxx_fetch_array because not all
 * databases support this function.
 *
 * <b>Note:</b> Use the {@link dbi_error()} function to get error information
 * if the connection fails.
 *
 * @param resource $res The database query resource returned from
 *                      the {@link dbi_query()} function.
 *
 * @return mixed An array of database columns representing a single row in
 *               the query result or false on an error.
 */
function dbi_fetch_row($res)
{
    if (strcmp($GLOBALS["db_type"], "mysql") == 0) {
        return mysql_fetch_array($res);
    } else {
        if (strcmp($GLOBALS["db_type"], "mysqli") == 0) {
            return mysqli_fetch_array($res);
        } else {
            if (strcmp($GLOBALS["db_type"], "mssql") == 0) {
                return mssql_fetch_array($res);
            } else {
                if (strcmp($GLOBALS["db_type"], "oracle") == 0) {
                    if (OCIFetchInto($GLOBALS["oracle_statement"], $row, OCI_NUM + OCI_RETURN_NULLS)) {
                        return $row;
                    }
                    return 0;
                } else {
                    if (strcmp($GLOBALS["db_type"], "postgresql") == 0) {
                        if (@$GLOBALS["postgresql_numrows[\"{$res}\"]"] > @$GLOBALS["postgresql_row[\"{$res}\"]"]) {
                            $r = pg_fetch_array($res, @$GLOBALS["postgresql_row[\"{$res}\"]"]);
                            @$GLOBALS["postgresql_row[\"{$res}\"]"]++;
                            if (!$r) {
                                echo "Unable to fetch row\n";
                                return '';
                            }
                        } else {
                            $r = '';
                        }
                        return $r;
                    } else {
                        if (strcmp($GLOBALS["db_type"], "odbc") == 0) {
                            if (!odbc_fetch_into($res, $ret)) {
                                return false;
                            }
                            return $ret;
                        } else {
                            if (strcmp($GLOBALS["db_type"], "ibm_db2") == 0) {
                                return db2_fetch_array($res);
                            } else {
                                if (strcmp($GLOBALS["db_type"], "ibase") == 0) {
                                    return ibase_fetch_row($res);
                                } else {
                                    dbi_fatal_error("dbi_fetch_row(): db_type not defined.");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 /**
  * @see ResultSet::next()
  */
 public function next()
 {
     $this->cursorPos++;
     if ($this->limit > 0 && $this->cursorPos > $this->limit) {
         $this->cursorPos = $this->limit + 1;
         return false;
     }
     $rowNum = $this->offset + $this->cursorPos;
     $fields = null;
     $cols = @odbc_fetch_into($this->result->getHandle(), $fields, $rowNum);
     if ($cols === false) {
         $this->cursorPos = -1;
         return false;
     }
     $this->fields =& $this->checkFetchMode($fields);
     return true;
 }
Пример #29
0
function xodbc_fetch_array($result, $rownumber, $limit)
{
    odbc_fetch_into($result, &$rs, $rownumber);
    $lim = 0;
    foreach ($rs as $key => $value) {
        if ($lim < $limit) {
            $rs_assoc[$key] = trim(iconv("cp1251", "UTF-8", $value));
            $lim++;
        } else {
        }
    }
    return $rs_assoc;
}
Пример #30
0
 /**
  * Returns number of rows in previous resultset. If no previous resultset exists,
  * this returns false.
  *
  * @return int Number of rows in resultset
  */
 function lastNumRows()
 {
     if ($this->hasResult()) {
         $counter = 0;
         if (@odbc_fetch_into($this->_result, $results)) {
             return count($results);
         } else {
             return null;
         }
     }
     return null;
 }