Exemplo n.º 1
0
 public function getAllFields($tablename)
 {
     $cur = sqlrcur_alloc($this->_conn);
     $success = sqlrcur_sendQuery($cur, SQLHelper::createSafeSQL("select * from :table", array(":table" => $tablename)));
     sqlrcon_endSession($cur);
     if (!$success) {
         throw new DatasetException(sqlrcur_errorMessage($cur));
     }
     $fields = [];
     $colCount = sqlrcur_colCount($cur);
     for ($col = 0; $col < $colCount; $col++) {
         $fields[] = strtolower(sqlrcur_getColumnName($cur, $col));
     }
     sqlrcur_free($cur);
     return $fields;
 }
Exemplo n.º 2
0
 /**
  * @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;
             }
         }
     }
 }
Exemplo n.º 3
0
<?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);
Exemplo n.º 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;
}
function da_sql_num_fields($fields, $config)
{
    return sqlrcur_colCount($fields);
}
 /**
  * Number of fields in the result set
  *
  * @access	public
  * @return	integer
  */
 function num_fields()
 {
     $count = sqlrcur_colCount($this->curs_id);
     if ($this->limit_used) {
         $count = $count - 1;
     }
     return $count;
 }