Exemplo n.º 1
0
 public static function castResult($result, array $a, Stub $stub, $isNested)
 {
     $a['num rows'] = pg_num_rows($result);
     $a['status'] = pg_result_status($result);
     if (isset(self::$resultStatus[$a['status']])) {
         $a['status'] = new ConstStub(self::$resultStatus[$a['status']], $a['status']);
     }
     $a['command-completion tag'] = pg_result_status($result, PGSQL_STATUS_STRING);
     if (-1 === $a['num rows']) {
         foreach (self::$diagCodes as $k => $v) {
             $a['error'][$k] = pg_result_error_field($result, $v);
         }
     }
     $a['affected rows'] = pg_affected_rows($result);
     $a['last OID'] = pg_last_oid($result);
     $fields = pg_num_fields($result);
     for ($i = 0; $i < $fields; ++$i) {
         $field = array('name' => pg_field_name($result, $i), 'table' => sprintf('%s (OID: %s)', pg_field_table($result, $i), pg_field_table($result, $i, true)), 'type' => sprintf('%s (OID: %s)', pg_field_type($result, $i), pg_field_type_oid($result, $i)), 'nullable' => (bool) pg_field_is_null($result, $i), 'storage' => pg_field_size($result, $i) . ' bytes', 'display' => pg_field_prtlen($result, $i) . ' chars');
         if (' (OID: )' === $field['table']) {
             $field['table'] = null;
         }
         if ('-1 bytes' === $field['storage']) {
             $field['storage'] = 'variable size';
         } elseif ('1 bytes' === $field['storage']) {
             $field['storage'] = '1 byte';
         }
         if ('1 chars' === $field['display']) {
             $field['display'] = '1 char';
         }
         $a['fields'][] = new EnumStub($field);
     }
     return $a;
 }
Exemplo n.º 2
0
 public function getColumnMeta($column)
 {
     if ($column >= $this->columnCount()) {
         return false;
     }
     $result = array();
     $result['native_type'] = pg_field_type($this->_result, $column);
     $result['table'] = pg_field_table($this->_result, $column);
     $result['name'] = pg_field_name($this->_result, $column);
     $result['len'] = pg_field_prtlen($this->_result, $column);
     $result['pdo_type'] = PDO::PARAM_STR;
     return $result;
 }
Exemplo n.º 3
0
 public function execute($sql)
 {
     // hide errors
     $ini_err = ini_get('display_errors');
     ini_set('display_errors', 0);
     $res = false;
     $this->res_errMsg = null;
     // --- process sql
     if ($this->dbType == 'postgres') {
         $this->res_data = pg_query($this->dbConn, $sql);
         if (!$this->res_data) {
             $this->res_errMsg = pg_last_error($this->dbConn);
         } else {
             $this->res_errMsg = pg_result_error($this->res_data);
             $this->res_affectedRows = pg_affected_rows($this->res_data);
             $this->res_rowCount = pg_num_rows($this->res_data);
             $this->res_fieldCount = pg_num_fields($this->res_data);
             $res = new dbRecordSet($this->dbType, $this->res_data, $this->res_rowCount, $this->res_fieldCount);
             // -- parse field names
             for ($i = 0; $i < $this->res_fieldCount; $i++) {
                 $this->res_fields[$i] = pg_field_name($this->res_data, $i);
                 $this->res_fieldsInfo[$i] = array();
                 $this->res_fieldsInfo[$i]['type'] = pg_field_type($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['len'] = pg_field_size($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['is_null'] = pg_field_is_null($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['prt_len'] = pg_field_prtlen($this->res_data, $i);
             }
         }
         // log error
         if ($this->res_errMsg != '') {
             // put here code to log error
         }
     }
     // --- mysql
     if ($this->dbType == 'mysql') {
         $this->res_data = mysql_query($sql, $this->dbConn);
         if (!$this->res_data) {
             $this->res_errMsg = mysql_error($this->dbConn);
         } else {
             @($this->res_errMsg = mysql_error($this->res_data));
             @($this->res_affectedRows = mysql_affected_rows($this->res_data));
             @($this->res_rowCount = mysql_num_rows($this->res_data));
             @($this->res_fieldCount = mysql_num_fields($this->res_data));
             @($res = new dbRecordSet($this->dbType, $this->res_data, $this->res_rowCount, $this->res_fieldCount));
             // -- parse field names
             for ($i = 0; $i < $this->res_fieldCount; $i++) {
                 $this->res_fields[$i] = mysql_field_name($this->res_data, $i);
                 $this->res_fieldsInfo[$i] = array();
                 $this->res_fieldsInfo[$i]['type'] = mysql_field_type($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['len'] = mysql_field_len($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['flags'] = mysql_field_flags($this->res_data, $i);
             }
         }
         // log error
         if ($this->res_errMsg != '') {
             // put here code to log error
         }
     }
     $this->res_sql = $sql;
     // show debug info if on
     if ($this->debug == true) {
         print "<pre>" . $sql . "<hr>";
         if ($this->res_errMsg != '') {
             print "<span style='color: red'>" . $this->res_errMsg . "</span><hr>";
         }
         print "</pre>";
     }
     // restore errors
     ini_set('display_errors', $ini_err);
     return $res;
 }
Exemplo n.º 4
0
 public function execute($sql)
 {
     global $sys_dbPrefix;
     global $ses_userid;
     // hide errors
     $ini_err = ini_get('display_errors');
     ini_set('display_errors', 0);
     $res = false;
     // --- process sql
     if ($this->dbType == 'postgres') {
         $this->res_data = pg_query($this->dbConn, $sql);
         if (!$this->res_data) {
             $this->res_errMsg = pg_last_error($this->dbConn);
         } else {
             $this->res_errMsg = pg_result_error($this->res_data);
             $this->res_affectedRows = pg_affected_rows($this->res_data);
             $this->res_rowCount = pg_num_rows($this->res_data);
             $this->res_fieldCount = pg_num_fields($this->res_data);
             $res = new phpRecordSet($this->dbType, $this->res_data, $this->res_rowCount, $this->res_fieldCount);
             // -- parse field names
             for ($i = 0; $i < $this->res_fieldCount; $i++) {
                 $this->res_fields[$i] = pg_field_name($this->res_data, $i);
                 $this->res_fieldsInfo[$i] = array();
                 $this->res_fieldsInfo[$i]['type'] = pg_field_type($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['len'] = pg_field_size($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['is_null'] = pg_field_is_null($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['prt_len'] = pg_field_prtlen($this->res_data, $i);
             }
         }
         // log error
         if ($this->res_errMsg != '') {
             $userid = $ses_userid != null ? $ses_userid : 'null';
             $ssql = "INSERT INTO " . $sys_dbPrefix . "log_error(domain, url, userid, sql, error)\n\t\t\t\t\t\t VALUES('" . $_SERVER["HTTP_HOST"] . "', '" . pg_escape_string($_SERVER["REQUEST_URI"]) . "', {$userid}, \n\t\t\t\t\t\t\t'" . pg_escape_string($sql) . "', '" . pg_escape_string($this->res_errMsg) . "');";
             pg_query($this->dbConn, $ssql);
         }
     }
     // --- mysql
     if ($this->dbType == 'mysql') {
         $this->res_data = mysql_query($sql, $this->dbConn);
         if (!$this->res_data) {
             $this->res_errMsg = mysql_error($this->dbConn);
         } else {
             $this->res_errMsg = mysql_error($this->res_data);
             $this->res_affectedRows = mysql_affected_rows($this->res_data);
             $this->res_rowCount = mysql_num_rows($this->res_data);
             $this->res_fieldCount = mysql_num_fields($this->res_data);
             $res = new phpRecordSet($this->dbType, $this->res_data, $this->res_rowCount, $this->res_fieldCount);
             // -- parse field names
             for ($i = 0; $i < $this->res_fieldCount; $i++) {
                 $this->res_fields[$i] = mysql_field_name($this->res_data, $i);
                 $this->res_fieldsInfo[$i] = array();
                 $this->res_fieldsInfo[$i]['type'] = mysql_field_type($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['len'] = mysql_field_len($this->res_data, $i);
                 $this->res_fieldsInfo[$i]['flags'] = mysql_field_flags($this->res_data, $i);
             }
         }
         // log error
         if ($this->res_errMsg != '') {
             $userid = $ses_userid != null ? $ses_userid : 'null';
             $ssql = "INSERT INTO " . $sys_dbPrefix . "log_error(domain, url, userid, sql, error)\n\t\t\t\t\t\t VALUES('" . $_SERVER["HTTP_HOST"] . "', '" . mysql_escape_string($_SERVER["REQUEST_URI"]) . "', {$userid}, \n\t\t\t\t\t\t\t'" . mysql_escape_string($sql) . "', '" . mysql_escape_string($this->res_errMsg) . "');";
             mysql_query($this->dbConn, $ssql);
         }
     }
     // show debug info if on
     if ($this->debug == true) {
         print "<pre>" . $sql . "<hr>";
         if ($this->res_errMsg != '') {
             print "<span style='color: red'>" . $this->res_errMsg . "</span><hr>";
         }
         print "</pre>";
     }
     // restore errors
     ini_set('display_errors', $ini_err);
     return $res;
 }
Exemplo n.º 5
0
 /**
  * Returns metadata for all columns in a result set.
  *
  * @return array
  */
 public function getColumnsMeta()
 {
     $hasTable = version_compare(PHP_VERSION, '5.2.0', '>=');
     $count = pg_num_fields($this->resultSet);
     $meta = array();
     for ($i = 0; $i < $count; $i++) {
         // items 'name' and 'table' are required
         $meta[] = array('name' => pg_field_name($this->resultSet, $i), 'table' => $hasTable ? pg_field_table($this->resultSet, $i) : NULL, 'type' => pg_field_type($this->resultSet, $i), 'size' => pg_field_size($this->resultSet, $i), 'prtlen' => pg_field_prtlen($this->resultSet, $i));
     }
     return $meta;
 }
Exemplo n.º 6
0
 public function field_data($table)
 {
     // TODO: This whole function needs to be debugged.
     $query = pg_query('SELECT * FROM ' . $this->escape_table($table) . ' LIMIT 1', $this->link);
     $fields = pg_num_fields($query);
     $table = array();
     for ($i = 0; $i < $fields; $i++) {
         $table[$i]['type'] = pg_field_type($query, $i);
         $table[$i]['name'] = pg_field_name($query, $i);
         $table[$i]['len'] = pg_field_prtlen($query, $i);
     }
     return $table;
 }
Exemplo n.º 7
0
    }
    for ($i = 0; $i < $rows; $i++) {
        pg_fetch_array($result, $i, PGSQL_NUM);
    }
    for ($i = 0; $i < $rows; $i++) {
        pg_fetch_object($result);
    }
    for ($i = 0; $i < $rows; $i++) {
        pg_fetch_row($result, $i);
    }
    for ($i = 0; $i < $rows; $i++) {
        pg_fetch_result($result, $i, 0);
    }
    pg_result_error($result);
    pg_num_rows(pg_execute($db, "php_test", array(100)));
    pg_num_fields(pg_execute($db, "php_test", array(100)));
    pg_field_name($result, 0);
    pg_field_num($result, $field_name);
    pg_field_size($result, 0);
    pg_field_type($result, 0);
    pg_field_prtlen($result, 0);
    pg_field_is_null($result, 0);
    $result = pg_prepare($db, "php_test2", "INSERT INTO " . $table_name . " VALUES (\$1, \$2);");
    pg_result_error($result);
    pg_free_result($result);
    $result = pg_execute($db, "php_test2", array(9999, "A'BC"));
    pg_last_oid($result);
    pg_free_result($result);
}
pg_close($db);
echo "OK";
Exemplo n.º 8
0
     $return['type'] = 'query';
     $command = stripslashes(trim($_GET['query']));
     $command_result = pg_query($player_connection, $command);
     if (!$command_result) {
         $return['error'][$error++] = nl2br(pg_last_error($player_connection));
         $return['error'][$error++] = nl2br($_GET['cmd']);
     } else {
         $return['affected_rows'] = pg_affected_rows($command_result);
         $return['num_rows'] = pg_num_rows($command_result);
         $return['column_count'] = pg_num_fields($command_result);
         for ($j = 0; $j < $return['column_count']; $j++) {
             $return['columns'] .= pg_field_name($command_result, $j) . ($j < $return['column_count'] - 1 ? ', ' : '');
             $return['columns_size'] .= '150' . ($j < $return['column_count'] - 1 ? ', ' : '');
             $return['columns_align'] .= 'right' . ($j < $return['column_count'] - 1 ? ', ' : '');
             $return['column'][$j]['name'] = pg_field_name($command_result, $j);
             $return['column'][$j]['size'] = pg_field_prtlen($command_result, $j);
             $return['column'][$j]['type'] = pg_field_type($command_result, $j);
         }
         if ($return['num_rows'] > 0) {
             for ($row = 0; $row < pg_num_rows($command_result); $row++) {
                 $return['rows'][$row]['id'] = $row;
                 for ($col = 0; $col < $return['column_count']; $col++) {
                     $return['rows'][$row]['data'][$col] = htmlspecialchars(pg_fetch_result($command_result, $row, $col));
                 }
             }
         }
     }
     break;
 case 'register':
     $return['type'] = 'register';
     $system_connection = pg_connect("host=db.schemaverse.com dbname=schemaverse user=schemaverse");