Ejemplo n.º 1
0
 function Tabler($table, $cols = array(), $filters = array(), $order = "")
 {
     $this->table($table);
     $this->pager = new Pager();
     if (count($cols) == 0) {
         $what = '*';
     } else {
         foreach ($cols as $title => $name) {
             if ($name != "") {
                 $this->addCol($name);
                 $this->col_option($name, 'title', $title);
             }
             $what .= $name . ',';
         }
         $what = substr($what, 0, strlen($what) - 1);
     }
     if (count($filters) > 0) {
         foreach ($filters as $add) {
             $filter = isset($filter) ? "{$filter} AND {$add}" : " WHERE {$add}";
         }
     }
     foreach ($_GET as $key => $value) {
         if (ereg('^filter_', $key)) {
             $name = substr($key, 7);
             if ($value != '') {
                 if ($_GET['f_' . $name . '_type'] == 'search') {
                     $filter = isset($filter) ? "{$filter} AND {$name} LIKE '%{$value}%'" : " WHERE {$name} LIKE '%{$value}%'";
                 } else {
                     $filter = isset($filter) ? "{$filter} AND {$name}='{$value}'" : " WHERE {$name}='{$value}'";
                 }
             }
         }
     }
     $query = "SELECT count(*) as max FROM {$table} {$filter}";
     $result = mysql_query($query) or die("MySQL Error: " . mysql_error());
     $row = mysql_fetch_array($result);
     $this->pager->max($row['max']);
     $query = "SELECT {$what} FROM {$table} {$filter}";
     $keys = array_keys($this->cols);
     $order = isset($_GET['orderby']) ? $_GET['orderby'] : ($order == "" ? $keys['0'] . ' DESC' : $order);
     $query .= " ORDER BY {$order}";
     $query .= " LIMIT " . $this->pager->from() . "," . $this->pager->incr();
     $result = mysql_query($query) or die("MySQL Error: " . mysql_error());
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         $this->add($row);
     }
     $fields = mysql_num_fields($result);
     for ($x = 0; $x < $fields; $x++) {
         $colinfo = @mysql_field_flags($result, $x);
         $colinfo = explode(' ', $colinfo);
         $name = mysql_field_name($result, $x);
         $type = mysql_field_type($result, $x);
         if (array_search('auto_increment', $colinfo) !== false) {
             $this->col_option($name, 'filter', 'submit');
             $this->idcol = $name;
         } else {
             $this->col_option($name, 'filter', 'select');
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @access	public
  * @return	array
  */
 function field_data()
 {
     $retval = array();
     for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) {
         $retval[$i] = new stdClass();
         $retval[$i]->name = mysql_field_name($this->result_id, $i);
         $retval[$i]->type = mysql_field_type($this->result_id, $i);
         $retval[$i]->max_length = mysql_field_len($this->result_id, $i);
         $retval[$i]->primary_key = strpos(mysql_field_flags($this->result_id, $i), 'primary_key') === FALSE ? 0 : 1;
         $retval[$i]->default = '';
     }
     /** Updated from github, see https://github.com/EllisLab/CodeIgniter/commit/effd0133b3fa805e21ec934196e8e7d75608ba00
     		while ($field = mysql_fetch_object($this->result_id))
     		{
     			preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
     
     			$type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
     			$length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
     
     			$F				= new stdClass();
     			$F->name		= $field->Field;
     			$F->type		= $type;
     			$F->default		= $field->Default;
     			$F->max_length	= $length;
     			$F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
     
     			$retval[] = $F;
     		}
     **/
     return $retval;
 }
function getAccessInfo($sql_fields, $sql_table, $sql_conditions = "1", $cond = NULL)
{
    $access['Data'] = array();
    $access['Headers'] = 0;
    $access['Sql_Fields'] = $sql_fields;
    $access['Sql_Table'] = $sql_table;
    $access['Sql_Conditions'] = $sql_conditions;
    $sql = "Select {$sql_fields} from {$sql_table} where {$sql_conditions}";
    $result = sql_query_read($sql) or dieLog(mysql_error() . " ~ " . "<pre>{$sql}</pre>");
    if (mysql_num_rows($result) < 1) {
        return -1;
    }
    $row = mysql_fetch_row($result);
    $fields = mysql_num_fields($result);
    for ($i = 0; $i < $fields; $i++) {
        $type = mysql_field_type($result, $i);
        $name = mysql_field_name($result, $i);
        $len = mysql_field_len($result, $i);
        $flags = mysql_field_flags($result, $i);
        $table = mysql_field_table($result, $i);
        $useName = $name;
        if (array_key_exists($useName, $access['Data'])) {
            $useName = $name . $i;
        }
        if ($name == 'access_header') {
            $access['Headers']++;
        }
        $access['Data'][$useName] = getAttrib($name, $type, $len, $flags, $table, $row[$i], &$cond);
    }
    return $access;
}
 public function getColumnMeta($column)
 {
     if ($column >= $this->columnCount()) {
         return false;
     }
     $info = mysql_fetch_field($this->_result, $column);
     $result = array();
     if ($info->def) {
         $result['mysql:def'] = $info->def;
     }
     $result['native_type'] = $info->type;
     $result['flags'] = explode(' ', mysql_field_flags($this->_result, $column));
     $result['table'] = $info->table;
     $result['name'] = $info->name;
     $result['len'] = mysql_field_len($this->_result, $column);
     $result['precision'] = 0;
     switch ($result['native_type']) {
         // seems like pdo_mysql treats everything as a string
         /*
          * case 'int': case 'real': $pdo_type =
          * EhrlichAndreas_Pdo_Abstract::PARAM_INT; break; case 'blob': $pdo_type =
          * EhrlichAndreas_Pdo_Abstract::PARAM_LOB; break; case 'null': $pdo_type =
          * EhrlichAndreas_Pdo_Abstract::PARAM_NULL; break;
          */
         default:
             $pdo_type = EhrlichAndreas_Pdo_Abstract::PARAM_STR;
             break;
     }
     $result['pdo_type'] = $pdo_type;
     return $result;
 }
Ejemplo n.º 5
0
 public function getFieldFlags($_model, $_variable_name)
 {
     $_result = mysql_query('SHOW COLUMNS FROM ' . strtolower($_model) . ' WHERE Field = "' . $_variable_name . '";');
     if (mysql_num_rows($_result) != 0) {
         return mysql_field_flags($_result, 0);
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * 1.4 betas were missing the 'binary' marker from logging.log_title,
  * which causes a collation mismatch error on joins in MySQL 4.1.
  *
  * @param $table String: table name
  * @param $field String: field name to check
  * @param $patchFile String: path to the patch to correct the field
  */
 protected function checkBin($table, $field, $patchFile)
 {
     $tableName = $this->db->tableName($table);
     $res = $this->db->query("SELECT {$field} FROM {$tableName} LIMIT 0", __METHOD__);
     $flags = explode(' ', mysql_field_flags($res->result, 0));
     if (in_array('binary', $flags)) {
         $this->output("...{$table} table has correct {$field} encoding.\n");
     } else {
         $this->applyPatch($patchFile, false, "Fixing {$field} encoding on {$table} table");
     }
 }
Ejemplo n.º 7
0
 function get_fields($query_id)
 {
     $fields = $this->num_fields($query_id);
     $rows = $this->num_rows($query_id);
     for ($i = 0; $i < $fields; $i++) {
         $field[$i]->type = mysql_field_type($query_id, $i);
         $field[$i]->name = mysql_field_name($query_id, $i);
         $field[$i]->len = mysql_field_len($query_id, $i);
         $field[$i]->flags = mysql_field_flags($query_id, $i);
     }
     return $field;
 }
Ejemplo n.º 8
0
 function getTablePrimeKey($pTable)
 {
     $this->connectDB();
     $fields = mysql_list_fields($this->mDatabaseName, $pTable, $this->mLink);
     $columns = mysql_num_fields($fields);
     for ($i = 0; $i < $columns; $i++) {
         $field_name = mysql_field_name($fields, $i);
         if (in_array("primary_key", explode(" ", mysql_field_flags($fields, $i)))) {
             $return[] = $field_name;
         }
     }
     return $return;
 }
Ejemplo n.º 9
0
 function readKeys($result)
 {
     $keys = array('primary' => array(), 'foreign' => array());
     $column_num = mysql_num_fields($result);
     for ($i = 0; $i < $column_num; $i++) {
         $column = mysql_field_name($result, $i);
         $table = mysql_field_table($result, $i);
         if (strpos(mysql_field_flags($result, $i), 'primary_key') > 0) {
             $type = 'primary';
             $keys[$type][$table] = array('type' => $type, 'table' => $table, 'column' => $column);
         }
     }
     return $keys;
 }
        case "mysql":
            $ret = mysql_field_len($result, $offset);
            break;
        case "mysqli":
            $tmp = mysqli_fetch_field_direct($result, $offset);
            $ret = $tmp->length;
            break;
    }
    return $ret;
}
function yog_mysql_field_flags($result, $offset)
{
    //Get the flags associated with the specified field in a result
    $ret = 0;
    switch (DB_EXTENSION) {
        case "mysql":
Ejemplo n.º 11
0
	function meta($table, $schema = "DEFAULT") {
		$db = $GLOBALS["CFG_DB"]->CON[$schema]->DB;
		$link = MysqlDriver::connect($schema);
		$result = mysql_list_fields($db, $table, $link);
		$count = mysql_num_fields($result);
		$fields = array();
		for($i = 0; $i < $count; $i++) {
			$field["name"] = mysql_field_name($result, $i);
			$field["length"] = mysql_field_len($result, $i);
			$field["type"] = mysql_field_type($result, $i);
			$field["flags"] = mysql_field_flags($result, $i);
			$fields[] = $field;
		}
		mysql_free_result($result);
		return $fields;
	}
Ejemplo n.º 12
0
 /**
  * @param String strSQL
  * @return Array
  */
 public function db_getfieldslist($strSQL)
 {
     $res = array();
     $qResult = $this->connectionObj->query($strSQL);
     $qHandle = $qResult->getQueryHandle();
     $fieldsNumber = $qResult->numFields();
     for ($i = 0; $i < $fieldsNumber; $i++) {
         $stype = mysql_field_type($qHandle, $i);
         if ($stype == "blob") {
             $flags = mysql_field_flags($qHandle, $i);
             if (strpos($flags, "binary") === false) {
                 $stype = "text";
             }
         }
         $ntype = $this->getFieldTypeNumber($stype);
         $res[$i] = array("fieldname" => $qResult->fieldName($i), "type" => $ntype, "not_null" => 0);
     }
     return $res;
 }
Ejemplo n.º 13
0
 function create_header()
 {
     $fields = mysql_list_fields($this->db, $this->table, $this->cnx);
     $h = "CREATE TABLE `" . $this->table . "` (";
     for ($i = 0; $i < mysql_num_fields($fields); $i++) {
         $name = mysql_field_name($fields, $i);
         $flags = mysql_field_flags($fields, $i);
         $len = mysql_field_len($fields, $i);
         $type = mysql_field_type($fields, $i);
         $h .= "`{$name}` {$type}({$len}) {$flags},";
         if (strpos($flags, "primary_key")) {
             $pkey = " PRIMARY KEY (`{$name}`)";
         }
     }
     $h = substr($h, 0, strlen($d) - 1);
     $h .= "{$pkey}) TYPE=InnoDB;\n\n";
     // echo "<p>--- Table data<br>$h</p>";
     return $h;
 }
Ejemplo n.º 14
0
 function getPrimaryFieldName($table_name)
 {
     global $db;
     $field = false;
     $sql = "SELECT * FROM " . TABLE_PREFIX . $table_name . ' WHERE 0';
     $result = mysql_query($sql, $db);
     $num_fields = mysql_num_fields($result);
     for ($i = 0; $i < $num_fields; $i++) {
         $flags = explode(' ', mysql_field_flags($result, $i));
         if (in_array('primary_key', $flags)) {
             if ($field == false) {
                 $field = mysql_field_name($result, $i);
             } else {
                 // there is more than one primary_key
                 return NULL;
             }
         }
     }
     return $field;
 }
Ejemplo n.º 15
0
 public function build()
 {
     $db = Database::get_instance();
     $values = $this->current_object->get_fields();
     $options = array();
     foreach ($values as $value) {
         $res = $db->query('SELECT `' . $value . '` FROM ' . $this->table)->result;
         $type = mysql_field_type($res, 0);
         $extra = mysql_field_flags($res, 0);
         $notnullsearch = strpos($extra, 'not_null');
         // If value can not be NULL lets add blank as a error check
         if ($notnullsearch === false) {
             $options['validation'] = '';
         } else {
             $options['validation'] = 'blank';
         }
         $options['type'] = $type === 'blob' ? 'htmleditor' : 'text';
         $options['type'] = $type === 'timestamp' ? 'timestamp' : $options['type'];
         $options['type'] = $value === 'password' ? 'password' : $options['type'];
         // Grab rows where field name matches
         $value_info = new Field_Information(array('table' => $this->table, 'name' => $value));
         if ($value_info->type !== NULL) {
             $options['type'] = $value_info->type;
             if ($options['type'] === 'file') {
                 // shouldn't validate for blank if it's a file.... TODO: Come up with a way to validate files
                 $options['validation'] = '';
             }
         }
         if ($value_info->options !== NULL) {
             $exploded_options = explode("\n", $value_info->options);
             foreach ($exploded_options as $option) {
                 if (!empty($option)) {
                     $option_temp = explode(',', $option);
                     $options['options'][$option_temp[0]] = $option_temp[1];
                 }
             }
         }
         $options['value'] = $this->current_object->{$value};
         $this->add_field($value, $options);
     }
 }
function db_getfieldslist($strSQL)
{
	global $conn;
	$res=array();
	$rs=db_query($strSQL,$conn);
	for($i=0;$i<db_numfields($rs);$i++)
	{
		$stype=mysql_field_type($rs,$i);
		if($stype=="blob")
		{
			$flags=mysql_field_flags($rs,$i);
			if(strpos($flags,"binary")===false)
				$stype="text";
		}

		$ntype=db_fieldtypenum($stype);
		$arr=mysql_fetch_field($rs,$i);
		$res[$i]=array("fieldname"=>db_fieldname($rs,$i),"type"=>$ntype,"not_null"=>0);
	}
	return $res;
}
Ejemplo n.º 17
0
 function getList($sqlQuery)
 {
     $retArr = array();
     $myResult = mysql_query($sqlQuery) or die("List Query failed - " . mysql_error());
     $numFields = mysql_num_fields($myResult);
     $c = 0;
     $primKeyFld = "";
     while ($rs = mysql_fetch_assoc($myResult)) {
         for ($i = 0; $i < $numFields; $i++) {
             $fldName = mysql_field_name($myResult, $i);
             $primKeyFldList = mysql_field_flags($myResult, $i);
             if (in_array("primary_key", explode(" ", $primKeyFldList))) {
                 $retArr[$c][$fldName][0] = true;
                 $retArr[$c][$fldName][1] = mysql_result($myResult, $c, $fldName);
             } else {
                 $retArr[$c][$fldName][0] = false;
                 $retArr[$c][$fldName][1] = mysql_result($myResult, $c, $fldName);
             }
         }
         $c++;
     }
     return $retArr;
 }
Ejemplo n.º 18
0
function ddfield($table)
{
    if (!empty($table)) {
        $result = mysql_query("select * from {$table}");
        $fields = mysql_num_fields($result);
        $rows = mysql_num_rows($result);
        $table = mysql_field_table($result, $k);
        $k = 0;
        echo "<b>Table Properties: Name: {$table}</b><br>";
        echo "<table border='1' cellpadding='4' cellspacing='2' width='80%'><tr><td><b>Field Name</b></td><td><b>Field Type</b></td><td><b>Field Length</b></td><td><b>Field Flags<b></td></tr>";
        while ($k < $fields) {
            echo "<tr>";
            $name = mysql_field_name($result, $k);
            $type = mysql_field_type($result, $k);
            $len = mysql_field_len($result, $k);
            $flags = mysql_field_flags($result, $k);
            echo "<td>" . $name . "</td><td>" . $type . "</td><td>" . $len . "</td><td>" . $flags . "</td>";
            $k++;
            echo "</tr>";
        }
        echo "</table>";
    }
}
Ejemplo n.º 19
0
function PMA_DBI_field_flags($result, $i)
{
    return mysql_field_flags($result, $i);
}
 if (!$db->getRowsNum($srs)) {
     die("You are not allowed to delete tables");
 }
 $export_string = '';
 while ($row_table = $db->fetchArray($srs)) {
     $table = $row_table['Name'];
     if (substr($table, 0, strlen($prefix) + 1) !== $prefix . '_') {
         continue;
     }
     $drs = $db->queryF("SHOW CREATE TABLE `{$table}`");
     $export_string .= "\nDROP TABLE IF EXISTS `{$table}`;\n" . mysql_result($drs, 0, 1) . ";\n\n";
     $result = mysql_query("SELECT * FROM `{$table}`");
     $fields_cnt = mysql_num_fields($result);
     $field_flags = array();
     for ($j = 0; $j < $fields_cnt; $j++) {
         $field_flags[$j] = mysql_field_flags($result, $j);
     }
     $search = array("", "\n", "\r", "");
     $replace = array('\\0', '\\n', '\\r', '\\Z');
     $current_row = 0;
     while ($row = mysql_fetch_row($result)) {
         $current_row++;
         for ($j = 0; $j < $fields_cnt; $j++) {
             $fields_meta = mysql_fetch_field($result, $j);
             // NULL
             if (!isset($row[$j]) || is_null($row[$j])) {
                 $values[] = 'NULL';
                 // a number
                 // timestamp is numeric on some MySQL 4.1
             } elseif ($fields_meta->numeric && $fields_meta->type != 'timestamp') {
                 $values[] = $row[$j];
Ejemplo n.º 21
0
 function FetchField($fieldOffset = -1)
 {
     if ($fieldOffset != -1) {
         $o = @mysql_fetch_field($this->_queryID, $fieldOffset);
         $f = @mysql_field_flags($this->_queryID, $fieldOffset);
         if ($o) {
             $o->max_length = @mysql_field_len($this->_queryID, $fieldOffset);
         }
         // suggested by: Jim Nicholson (jnich#att.com)
         //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
         if ($o) {
             $o->binary = strpos($f, 'binary') !== false;
         }
     } else {
         if ($fieldOffset == -1) {
             /*	The $fieldOffset argument is not provided thus its -1 	*/
             $o = @mysql_fetch_field($this->_queryID);
             if ($o) {
                 $o->max_length = @mysql_field_len($this->_queryID);
             }
             // suggested by: Jim Nicholson (jnich#att.com)
             //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
         }
     }
     return $o;
 }
Ejemplo n.º 22
0
 /**
  * Returns information about a table or a result set
  *
  * @param object|string  $result  MDB2_result object from a query or a
  *                                 string containing the name of a table.
  *                                 While this also accepts a query result
  *                                 resource identifier, this behavior is
  *                                 deprecated.
  * @param int            $mode    a valid tableInfo mode
  *
  * @return array  an associative array with the information requested.
  *                 A MDB2_Error object on failure.
  *
  * @see MDB2_Driver_Common::setOption()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         return parent::tableInfo($result, $mode);
     }
     $db =& $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
     if (!is_resource($resource)) {
         return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'Could not generate result resource', __FUNCTION__);
     }
     if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
         if ($db->options['field_case'] == CASE_LOWER) {
             $case_func = 'strtolower';
         } else {
             $case_func = 'strtoupper';
         }
     } else {
         $case_func = 'strval';
     }
     $count = @mysql_num_fields($resource);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     $db->loadModule('Datatype', null, true);
     for ($i = 0; $i < $count; $i++) {
         $res[$i] = array('table' => $case_func(@mysql_field_table($resource, $i)), 'name' => $case_func(@mysql_field_name($resource, $i)), 'type' => @mysql_field_type($resource, $i), 'length' => @mysql_field_len($resource, $i), 'flags' => @mysql_field_flags($resource, $i));
         if ($res[$i]['type'] == 'string') {
             $res[$i]['type'] = 'char';
         } elseif ($res[$i]['type'] == 'unknown') {
             $res[$i]['type'] = 'decimal';
         }
         $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
         if (PEAR::isError($mdb2type_info)) {
             return $mdb2type_info;
         }
         $res[$i]['mdb2type'] = $mdb2type_info[0][0];
         if ($mode & MDB2_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     return $res;
 }
Ejemplo n.º 23
0
 /**
  * Returns information about a table or a result set
  *
  * @param object|string  $result  DB_result object from a query or a
  *                                 string containing the name of a table.
  *                                 While this also accepts a query result
  *                                 resource identifier, this behavior is
  *                                 deprecated.
  * @param int            $mode    a valid tableInfo mode
  *
  * @return array  an associative array with the information requested.
  *                 A DB_Error object on failure.
  *
  * @see DB_common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         $id = @mysql_list_fields($this->dsn['database'], $result, $this->connection);
         $got_string = true;
     } elseif (isset($result->result)) {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->result;
         $got_string = false;
     } else {
         /*
          * Probably received a result resource identifier.
          * Copy it.
          * Deprecated.  Here for compatibility only.
          */
         $id = $result;
         $got_string = false;
     }
     if (!is_resource($id)) {
         return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA);
     }
     if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     $count = @mysql_num_fields($id);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     for ($i = 0; $i < $count; $i++) {
         $res[$i] = array('table' => $case_func(@mysql_field_table($id, $i)), 'name' => $case_func(@mysql_field_name($id, $i)), 'type' => @mysql_field_type($id, $i), 'len' => @mysql_field_len($id, $i), 'flags' => @mysql_field_flags($id, $i));
         if ($mode & DB_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & DB_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     // free the result only if we were called on a table
     if ($got_string) {
         @mysql_free_result($id);
     }
     return $res;
 }
   $row_table_def['True_Type'] = ereg_replace('\\(.*', '', $row_table_def['Type']);
   if ($AFFALL=="vrai") echo " ;epur� ".$row_table_def['True_Type']."<BR>";
   if (strstr($row_table_def['True_Type'], 'enum')) {
         $enum        = str_replace('enum(', '', $row_table_def['Type']);
         $enum        = ereg_replace('\\)$', '', $enum);
         $enum        = explode('\',\'', substr($enum, 1, -1));
         $enum_cnt    = count($enum);
     if ($AFFALL=="vrai") {
        echo "Liste de valeurs enum: ";
        for ($l=0;$l<$enum_cnt;$l++) {
          echo $enum[$l]." - ";      
          }
        echo "<BR>";
        }
     } // fin si �um
   if ($AFFALL=="vrai" && $_SESSION[db_type]=="mysql") echo "Flags MySql:".mysql_field_flags ($resf, $j)."<BR>";
   echo "</TD>";
   
   $LIBELLE=RecupLib($TBDname,"NM_CHAMP","LIBELLE",$NM_CHAMP);
   echo "<TD>".($LIBELLE!="" ? $LIBELLE : "&nbsp;")."</TD>";
   $TYPEAFF=RecupLib($TBDname,"NM_CHAMP","TYPEAFF",$NM_CHAMP);
   echo "<TD>".$TYPEAFF."</TD>";
   $VALEURS=RecupLib($TBDname,"NM_CHAMP","VALEURS",$NM_CHAMP);
   echo "<TD>".($VALEURS!="" ? $VALEURS : "&nbsp;")."</TD>";      
   $COMMENT=RecupLib($TBDname,"NM_CHAMP",$GLOBALS["NmChpComment"],$NM_CHAMP);
   echo "<TD>".($COMMENT!="" ? $COMMENT : "&nbsp;")."</TD>";      
   
   echo "</TR>";
   } // fin boucle sur les champs de la table
 echo "</TABLE>";
 echo '<p><a href="admdesct.php?lc_NM_TABLE='.$NM_TABLE.'">Editer les propriétés de cette table</a></p>';
Ejemplo n.º 25
0
 function metadata($table = "", $full = false)
 {
     $count = 0;
     $id = 0;
     $res = array();
     /*
      * Due to compatibility problems with Table we changed the behavior
      * of metadata();
      * depending on $full, metadata returns the following values:
      *
      * - full is false (default):
      * $result[]:
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *
      * - full is true
      * $result[]:
      *   ["num_fields"] number of metadata records
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *   ["meta"][field name]  index of field named "field name"
      *   This last one could be used if you have a field name, but no index.
      *   Test:  if (isset($result['meta']['myfield'])) { ...
      */
     // if no $table specified, assume that we are working with a query
     // result
     if ($table) {
         $this->connect();
         $id = mysql_list_fields($this->Database, $table);
         if (!$id) {
             $this->halt("Metadata query failed.");
             return false;
         }
     } else {
         $id = $this->Query_ID;
         if (!$id) {
             $this->halt("No query specified.");
             return false;
         }
     }
     $count = mysql_num_fields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (!$full) {
         for ($i = 0; $i < $count; $i++) {
             $res[$i]["table"] = mysql_field_table($id, $i);
             $res[$i]["name"] = mysql_field_name($id, $i);
             $res[$i]["type"] = mysql_field_type($id, $i);
             $res[$i]["len"] = mysql_field_len($id, $i);
             $res[$i]["flags"] = mysql_field_flags($id, $i);
         }
     } else {
         // full
         $res["num_fields"] = $count;
         for ($i = 0; $i < $count; $i++) {
             $res[$i]["table"] = mysql_field_table($id, $i);
             $res[$i]["name"] = mysql_field_name($id, $i);
             $res[$i]["type"] = mysql_field_type($id, $i);
             $res[$i]["len"] = mysql_field_len($id, $i);
             $res[$i]["flags"] = mysql_field_flags($id, $i);
             $res["meta"][$res[$i]["name"]] = $i;
         }
     }
     // free the result only if we were called on a table
     if ($table) {
         #mysql_free_result($id);
         $this->free();
     }
     return $res;
 }
Ejemplo n.º 26
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;
 }
Ejemplo n.º 27
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;
 }
Ejemplo n.º 28
0
 /**
  * Test mysql_field_flags
  *
  * @return boolean
  */
 public function MySQL_Field_Flags_Test()
 {
     // Select Db
     $this->_selectDb();
     // Query
     $sql = 'SELECT * FROM ' . TEST_TABLE . ' LIMIT 1';
     // Query
     $query1 = mysql_query($sql);
     $query2 = $this->_object->mysql_query($sql);
     // Get items
     $flags1 = mysql_field_flags($query1, 0);
     $flags2 = $this->_object->mysql_field_flags($query2, 0);
     return $flags1 === $flags2;
 }
Ejemplo n.º 29
0
     $n = mysql_fetch_array(mysql_query(preg_replace('/^\\s*select\\s+.+\\s+from\\s+/i', 'select count(*) from', $_POST['querysql'])));
     $result = mysql_query($_POST['querysql'], $connect);
 } else {
     $n = mysql_fetch_array(mysql_query('select count(*) from ' . $_POST['table_sel']));
     $sort = '';
     if (!empty($_POST['sort'])) {
         $sort = 'ORDER BY `' . trim($_POST['sort']) . '` ASC ';
     }
     $co = '0,20';
     if (isset($_POST['br_st']) && isset($_POST['br_en'])) {
         $co = $_POST['br_en'] . ',' . $_POST['br_st'];
     }
     $result = mysql_query("SELECT * FROM `" . $_POST['table_sel'] . "` {$sort} limit {$co}", $connect);
 }
 for ($i = 0; $i < mysql_num_fields($result); $i++) {
     if (ereg('primary_key', mysql_field_flags($result, $i))) {
         $prim = mysql_field_name($result, $i);
     }
 }
 $up_e = '';
 echo "<div style='width:100%;height:450px;overflow:auto;'><table border=1>\n";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
     echo "<tr bgcolor='#C1D2C5'>\n";
     if (!isset($lk)) {
         echo "<td><b>EDIT</b></td>";
         foreach (array_keys($line) as $lk) {
             print isset($prim) && $lk === $prim ? "<td><u><b>{$lk}</b></u></td>" : "<td>{$lk}</td>\n";
         }
     }
     if (!isset($prim)) {
         while (list($key, $val) = each($line)) {
Ejemplo n.º 30
0
 /**
  ** Fetch field flags (works off of db_list_fiels())
  **
  **/
 function db_field_flags($qid = false, $field_num = '')
 {
     if ($qid === false) {
         return false;
     }
     if (!is_numeric($field_num)) {
         return false;
     }
     return mysql_field_flags($qid, $field_num);
 }