コード例 #1
0
ファイル: DBSQLRelayDriver.php プロジェクト: byjg/anydataset
 public function getScalar($sql, $array = null)
 {
     $cur = $this->getSQLRelayCursor($sql, $array);
     $scalar = sqlrcur_getField($cur, 0, 0);
     sqlrcur_free($cur);
     return $scalar;
 }
コード例 #2
0
ファイル: SQLRelayIterator.php プロジェクト: byjg/anydataset
 /**
  * @return bool
  */
 public function hasNext()
 {
     if (count($this->_rowBuffer) >= SQLRelayIterator::RECORD_BUFFER) {
         return true;
     } else {
         if (is_null($this->_cursor)) {
             return count($this->_rowBuffer) > 0;
         } else {
             if ($this->_currentRow < $this->count()) {
                 $sr = new SingleRow();
                 $colCount = sqlrcur_colCount($this->_cursor);
                 for ($col = 0; $col < $colCount; $col++) {
                     $fieldName = strtolower(sqlrcur_getColumnName($this->_cursor, $col));
                     $value = sqlrcur_getField($this->_cursor, $this->_currentRow, $col);
                     if (is_null($value)) {
                         $sr->addField($fieldName, "");
                     } elseif (is_object($value)) {
                         $sr->addField($fieldName, "[OBJECT]");
                     } else {
                         $value = AnyDataset::fixUTF8($value);
                         $sr->addField($fieldName, $value);
                     }
                 }
                 $this->_currentRow++;
                 // Enfileira o registo
                 array_push($this->_rowBuffer, $sr);
                 // Traz novos até encher o Buffer
                 if (count($this->_rowBuffer) < DBIterator::RECORD_BUFFER) {
                     $this->hasNext();
                 }
                 return true;
             } else {
                 sqlrcur_free($this->_cursor);
                 $this->_cursor = null;
                 return count($this->_rowBuffer) > 0;
             }
         }
     }
 }
コード例 #3
0
ファイル: sqlrelay.php プロジェクト: billfeller/frontfunc
<?php

$con = sqlrcon_alloc('mysqlpool', 12000, '/tmp/mysqlpool.socket', 'root', '******', 0, 1);
var_dump(sqlrcon_errorNumber($con));
var_dump(sqlrcon_dbHostName($con));
var_dump(sqlrcon_dbIpAddress($con));
$cur = sqlrcur_alloc($con);
sqlrcur_sendQuery($cur, 'select * from test');
var_dump(sqlrcur_totalRows($cur));
for ($row = 0; $row < sqlrcur_rowCount($cur); $row++) {
    for ($col = 0; $col < sqlrcur_colCount($cur); $col++) {
        echo sqlrcur_getField($cur, $row, $col);
    }
    echo PHP_EOL;
}
sqlrcur_free($cur);
sqlrcon_free($con);
コード例 #4
0
/**
 * Perform a DB Layer SQL query.
 *
 * This function returns values dependin on the input parameters and the result of the query.
 * It can return:
 *   false if there was an error,
 *   true if the query succeeded but did not generate any rows
 *   array of field values if it returned a single row and $single is true
 *   array of array of field values if it returned row(s) [stacked array]
 *
 * @access public
 * @param   string      SQL query to execute
 * @param   boolean     Toggle whether the expected result is a single row (TRUE) or multiple rows (FALSE). This affects whether the returned array is 1 or 2 dimensional!
 * @param   string      Result type of the array indexing. Can be one of "assoc" (associative), "num" (numerical), "both" (numerical and associative, default)
 * @param   boolean     If true, errors will be reported. If false, errors will be ignored.
 * @param   string      A possible array key name, so that you can control the multi-dimensional mapping of an array by the key column
 * @param   string      A possible array field name, so that you can control the multi-dimensional mapping of an array by the key column and the field value.
 * @param   boolean     If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignroed on DUPLICATE INDEX queries and the likes)
 * @return  mixed       Returns the result of the SQL query, depending on the input parameters
 */
function generate_resultset($cursor, $result_type = 'sqlr_BOTH')
{
    $return_row = array();
    for ($r_row = 0, $max_r = sqlrcur_rowCount($cursor); $r_row < $max_r; $r_row++) {
        for ($r_col = 0, $max_rc = sqlrcur_colCount($cursor); $r_col < $max_rc; $r_col++) {
            if ($result_type == 'sqlr_ASSOC') {
                $return_row[sqlrcur_getColumnName($cursor, $r_col)] = sqlrcur_getField($cursor, $r_row, $r_col);
            } else {
                $return_row[$r_row][$r_col] = sqlrcur_getField($cursor, $r_row, $r_col);
                $return_row[$r_row][sqlrcur_getColumnName($cursor, $r_col)] = $return_row[$r_row][$r_col];
            }
        }
    }
    return $return_row;
}
コード例 #5
0
 /**
  * Returns a string with value of the specified row and column
  *
  * @access public
  * @param  integer $iRow
  * @param  integer $iCol
  * @return string
  */
 function getSpecificField($iRow, $iCol)
 {
     return sqlrcur_getField($this->curs_id, $iRow, $iCol);
 }