Esempio n. 1
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;
 }
Esempio n. 4
0
 function import($data)
 {
     // cette méthode prend en entrée un tableau constitué des informations suivantes :
     //	$data['statut_libelle']
     //	$data['pret_flag']
     //	$data['statusdoc_codage_import']
     //	$data['statusdoc_owner']
     global $dbh;
     // check sur le type de  la variable passée en paramètre
     if (!sizeof($data) || !is_array($data)) {
         // si ce n'est pas un tableau ou un tableau vide, on retourne 0
         return 0;
     }
     // check sur les éléments du tableau
     $long_maxi = mysql_field_len(mysql_query("SELECT statut_libelle FROM docs_statut limit 1"), 0);
     $data['statut_libelle'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['statut_libelle']))), 0, $long_maxi));
     $long_maxi = mysql_field_len(mysql_query("SELECT statusdoc_codage_import FROM docs_statut limit 1"), 0);
     $data['statusdoc_codage_import'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['statusdoc_codage_import']))), 0, $long_maxi));
     if ($data['statusdoc_owner'] == "") {
         $data['statusdoc_owner'] = 0;
     }
     if ($data['statut_libelle'] == "") {
         return 0;
     }
     /* statusdoc_codage_import est obligatoire si statusdoc_owner != 0 */
     if ($data['statusdoc_owner'] != 0 && $data['statusdoc_codage_import'] == "") {
         return 0;
     }
     // préparation de la requête
     $key0 = addslashes($data['statut_libelle']);
     $key1 = addslashes($data['statusdoc_codage_import']);
     $key2 = $data['statusdoc_owner'];
     /* vérification que le statut existe */
     $query = "SELECT idstatut FROM docs_statut WHERE statusdoc_codage_import='{$key1}' and statusdoc_owner = '{$key2}' LIMIT 1 ";
     $result = @mysql_query($query, $dbh);
     if (!$result) {
         die("can't SELECT docs_statut " . $query);
     }
     $docs_statut = mysql_fetch_object($result);
     /* le statut de doc existe, on retourne l'ID */
     if ($docs_statut->idstatut) {
         return $docs_statut->idstatut;
     }
     // id non-récupérée, il faut créer la forme.
     /* une petite valeur par défaut */
     if ($data['pret_flag'] == "") {
         $data['pret_flag'] = 1;
     }
     $query = "INSERT INTO docs_statut SET ";
     $query .= "statut_libelle='" . $key0 . "', ";
     $query .= "pret_flag='" . $data['pret_flag'] . "', ";
     $query .= "statusdoc_codage_import='" . $key1 . "', ";
     $query .= "statusdoc_owner='" . $key2 . "' ";
     $result = @mysql_query($query, $dbh);
     if (!$result) {
         die("can't INSERT into docs_statut " . $query);
     }
     return mysql_insert_id($dbh);
 }
Esempio n. 5
0
 function import($data)
 {
     // cette méthode prend en entrée un tableau constitué des informations suivantes :
     //	$data['section_libelle']
     //	$data['sdoc_codage_import']
     //	$data['sdoc_owner']
     global $dbh;
     // check sur le type de  la variable passée en paramètre
     if (!sizeof($data) || !is_array($data)) {
         // si ce n'est pas un tableau ou un tableau vide, on retourne 0
         return 0;
     }
     // check sur les éléments du tableau
     $long_maxi = mysql_field_len(mysql_query("SELECT section_libelle FROM docs_section limit 1"), 0);
     $data['section_libelle'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['section_libelle']))), 0, $long_maxi));
     $long_maxi = mysql_field_len(mysql_query("SELECT sdoc_codage_import FROM docs_section limit 1"), 0);
     $data['sdoc_codage_import'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['sdoc_codage_import']))), 0, $long_maxi));
     if ($data['sdoc_owner'] == "") {
         $data['sdoc_owner'] = 0;
     }
     if ($data['section_libelle'] == "") {
         return 0;
     }
     /* sdoc_codage_import est obligatoire si sdoc_owner != 0 */
     // if(($data['sdoc_owner']!=0) && ($data['sdoc_codage_import']=="")) return 0;
     // préparation de la requête
     $key0 = addslashes($data['section_libelle']);
     $key1 = addslashes($data['sdoc_codage_import']);
     $key2 = $data['sdoc_owner'];
     /* vérification que la section existe */
     $query = "SELECT idsection FROM docs_section WHERE sdoc_codage_import='{$key1}' and sdoc_owner = '{$key2}' LIMIT 1 ";
     $result = @mysql_query($query, $dbh);
     if (!$result) {
         die("can't SELECT docs_section " . $query);
     }
     $docs_section = mysql_fetch_object($result);
     /* le type de doc existe, on retourne l'ID */
     if ($docs_section->idsection) {
         return $docs_section->idsection;
     }
     // id non-récupérée, il faut créer la forme.
     $query = "INSERT INTO docs_section SET ";
     $query .= "section_libelle='" . $key0 . "', ";
     $query .= "sdoc_codage_import='" . $key1 . "', ";
     $query .= "sdoc_owner='" . $key2 . "' ";
     $result = @mysql_query($query, $dbh);
     if (!$result) {
         die("can't INSERT into docs_section " . $query);
     }
     $id_section_cree = mysql_insert_id($dbh);
     $query = "insert into docsloc_section (SELECT {$id_section_cree}, idlocation FROM docs_location) ";
     $result = @mysql_query($query, $dbh);
     return $id_section_cree;
 }
Esempio n. 6
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;
 }
function ep4_zen_field_length($tbl, $fld)
{
    global $db;
    $project = PROJECT_VERSION_MAJOR . '.' . PROJECT_VERSION_MINOR;
    $ep_uses_mysqli = PROJECT_VERSION_MAJOR > '1' || PROJECT_VERSION_MINOR >= '5.3' ? true : false;
    $meta = array();
    $result = $ep_uses_mysqli ? mysqli_query("SELECT {$fld} FROM {$tbl}") : mysql_query("SELECT {$fld} FROM {$tbl}");
    if (!$result) {
        echo 'Could not run query: ' . ($ep_uses_mysqli ? mysqli_error($db->link) : mysql_error());
        exit;
    }
    $length = $ep_uses_mysqli ? mysqli_field_len($result, 0) : mysql_field_len($result, 0);
    return $length;
}
Esempio n. 8
0
 function getTableFieldHash($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);
         $return[$field_name]['name'] = $field_name;
         $return[$field_name]['type'] = mysql_field_type($fields, $i);
         $return[$field_name]['length'] = mysql_field_len($fields, $i);
         $return[$field_name]['flags'] = explode(" ", mysql_field_flags($fields, $i));
     }
     return $return;
 }
Esempio n. 9
0
 function import($data)
 {
     // cette méthode prend en entrée un tableau constitué des informations suivantes :
     //	$data['nom']
     //	$data['pays']
     //	$data['diffusion']
     global $dbh;
     // check sur le type de  la variable passée en paramètre
     if (!sizeof($data) || !is_array($data)) {
         // si ce n'est pas un tableau ou un tableau vide, on retourne 0
         return 0;
     }
     // check sur les éléments du tableau
     $long_maxi = mysql_field_len(mysql_query("SELECT orinot_nom FROM origine_notice "), 0);
     $data['nom'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['nom']))), 0, $long_maxi));
     $long_maxi = mysql_field_len(mysql_query("SELECT orinot_pays FROM origine_notice "), 0);
     $data['pays'] = rtrim(substr(preg_replace('/\\[|\\]/', '', rtrim(ltrim($data['pays']))), 0, $long_maxi));
     if ($data['diffusion'] == "") {
         $data['diffusion'] = 1;
     }
     if ($data['nom'] == "") {
         return 0;
     }
     // préparation de la requête
     $key0 = addslashes($data['nom']);
     $key1 = addslashes($data['pays']);
     $key2 = $data['diffusion'];
     /* vérification que le statut existe */
     $query = "SELECT orinot_id FROM origine_notice WHERE orinot_nom='{$key0}' and orinot_pays = '{$key1}' LIMIT 1 ";
     $result = @mysql_query($query, $dbh);
     if (!$result) {
         die("can't SELECT origine_notice " . $query);
     }
     $origine_notice = mysql_fetch_object($result);
     /* le statut de doc existe, on retourne l'ID */
     if ($origine_notice->orinot_id) {
         return $origine_notice->orinot_id;
     }
     // id non-récupérée, il faut créer la forme.
     $query = "INSERT INTO origine_notice SET ";
     $query .= "orinot_nom='" . $key0 . "', ";
     $query .= "orinot_pays='" . $key1 . "', ";
     $query .= "orinot_diffusion='" . $key2 . "' ";
     $result = @mysql_query($query, $dbh);
     if (!$result) {
         die("can't INSERT into origine_notice " . $query);
     }
     return mysql_insert_id($dbh);
 }
        case "mysql":
            $ret = mysql_field_type($result, $offset);
            break;
        case "mysqli":
            $tmp = mysqli_fetch_field_direct($result, $offset);
            $ret = GetCorrectDataTypeMySQLI($tmp->type);
            break;
    }
    return $ret;
}
function yog_mysql_field_len($result, $offset)
{
    //Returns the length of the specified field
    $ret = 0;
    switch (DB_EXTENSION) {
Esempio 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;
	}
Esempio n. 12
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;
 }
Esempio n. 13
0
File: table.php Progetto: sembrono/1
 function mysql_fetch_fields($tb)
 {
     // LIMIT 1 means to only read rows before row 1 (0-indexed)
     $result = mysql_query("SELECT * FROM `{$tb}` LIMIT 0");
     $describe = mysql_query("SHOW COLUMNS FROM `{$tb}`");
     $num = mysql_num_fields($result);
     $output = array();
     for ($i = 0; $i < $num; ++$i) {
         $field = mysql_fetch_field($result, $i);
         // Analyze 'extra' field
         $field->auto_increment = strpos(mysql_result($describe, $i, 'Extra'), 'auto_increment') === FALSE ? 0 : 1;
         // Create the column_definition
         $field->definition = mysql_result($describe, $i, 'Type');
         if ($field->not_null && !$field->primary_key) {
             $field->definition .= ' NOT NULL';
         }
         $avmi = mysql_result($describe, $i, 'Default');
         if ($avmi != "" && $avmi != "NULL") {
             $field->def = $avmi;
         } else {
             $field->def = false;
         }
         if ($field->def) {
             $field->definition .= " DEFAULT '" . mysql_real_escape_string($field->def) . "'";
         }
         if ($field->auto_increment) {
             $field->definition .= ' AUTO_INCREMENT';
         }
         if ($key = mysql_result($describe, $i, 'Key')) {
             if ($field->primary_key) {
                 $field->definition .= ' PRIMARY KEY';
             } else {
                 $field->definition .= ' UNIQUE KEY';
             }
         }
         // Create the field length
         $field->len = mysql_field_len($result, $i);
         // Store the field into the output
         $output[$field->name] = $field;
     }
     return $output;
 }
Esempio n. 14
0
function kdauto($tabel, $inisial)
{
    $struktur = mysql_query("SELECT * FROM {$tabel}");
    $field = mysql_field_name($struktur, 0);
    $panjang = mysql_field_len($struktur, 0);
    $qry = mysql_query("SELECT max(" . $field . ") FROM " . $tabel);
    $row = mysql_fetch_array($qry);
    if ($row[0] == "") {
        $angka = 0;
    } else {
        $angka = substr($row[0], strlen($inisial));
    }
    $angka++;
    $angka = strval($angka);
    $tmp = "";
    for ($i = 1; $i <= $panjang - strlen($inisial) - strlen($angka); $i++) {
        $tmp = $tmp . "0";
    }
    return $inisial . $tmp . $angka;
}
function ubrows($lc_sql)
{
    //$lc_sql為mysql_query()所傳回的變數
    $m_field = mysql_num_fields($lc_sql);
    //求出查詢的sql命令中共有幾個欄位
    $m_table = '<table  border="1" align="center" cellspacing="0" ><tr bgcolor="#CCFF66">';
    for ($m_l = 0; $m_l < $m_field; $m_l++) {
        $m_str = mysql_field_name($lc_sql, $m_l);
        $m_table = $m_table . '<td ><span style="font-size:18px">&nbsp;' . $m_str . '</span></td>';
    }
    $m_table = $m_table . '</tr>';
    $m_i = 0;
    while ($m_record = mysql_fetch_array($lc_sql)) {
        $m_color = '#DDFFCC';
        if (bcmod($m_i, 2) == 0) {
            $m_color = "FFFFFF";
            //資料第一筆,就使用白色,第二筆淺綠色,第三筆白色,以此類推
        }
        $m_table = $m_table . '<tr bgcolor="' . $m_color . '">';
        for ($m_k = 0; $m_k < $m_field; $m_k++) {
            //$m_field為此sql命令的欄位總數
            $m_str = mysql_field_name($lc_sql, $m_k);
            $m_type = mysql_field_type($lc_sql, $m_k);
            //指定欄位的型態
            $m_len = mysql_field_len($lc_sql, $m_k);
            //指定欄位的長度
            $m_table = $m_table . '<td ><span style="font-size:13px">&nbsp;' . $m_record[$m_k] . '</span></td>';
        }
        $m_table = $m_table . "</tr>";
        $m_i = $m_i + 1;
    }
    $m_table = $m_table . "</table>";
    echo "<script>\r\n\t\t\tvar writeWin = null;\r\n\t\t\tfunction writeLeft() { \r\n\r\n\t\t\t\twriteWin =window.open('','aWin','top=50%,left=50%,width=700,status=yes,toolbars=yes,scrollbars=yes,menubar=yes,directories=yes,resizable=yes'); \r\n\t\t\t\tvar ePen ='" . $m_table . "';\r\n\t\t\t\twriteWin.document.open();\r\n\t\t\t\twriteWin.document.write(ePen);\r\n\t\t\t\twriteWin.document.close();\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t</script>";
    //window視窗物件
    //menubar-->功能表列 [例如] [檔案] [編輯] [檢視] [我的最愛] .. 等 這些按鈕,若沒有設定,則預設為隱藏
    //scrollbars-->上下拉式卷軸 若沒有設定則設為只顯示視窗大小的內容
    //resizable為是否允許使用者改變視窗大小,若不設定,預設為不允許
    echo "<script>writeLeft();</script>";
}
Esempio n. 16
0
function buatKode($tabel, $inisial)
{
    $struktur = mysql_query("SELECT * FROM {$tabel}");
    $field = mysql_field_name($struktur, 0);
    $panjang = mysql_field_len($struktur, 0);
    // membaca panjang kolom
    $hasil = mysql_fetch_field($struktur, 0);
    //$panjang	= $hasil->max_length;
    $qry = mysql_query("SELECT MAX(" . $field . ") FROM " . $tabel);
    $row = mysql_fetch_array($qry);
    if ($row[0] == "") {
        $angka = 0;
    } else {
        $angka = substr($row[0], strlen($inisial));
    }
    $angka++;
    $angka = strval($angka);
    $tmp = "";
    for ($i = 1; $i <= $panjang - strlen($inisial) - strlen($angka); $i++) {
        $tmp = $tmp . "0";
    }
    return $inisial . $tmp . $angka;
}
Esempio n. 17
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;
 }
Esempio n. 18
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;
 }
Esempio n. 19
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;
 }
Esempio n. 20
0
 /**
  * Test mysql_field_len
  *
  * @return boolean
  */
 public function MySQL_Field_Len_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
     $length1 = mysql_field_len($query1, 0);
     $length2 = $this->_object->mysql_field_len($query2, 0);
     return $length1 === $length2;
 }
Esempio n. 21
0
function PMA_DBI_field_len($result, $i)
{
    return mysql_field_len($result, $i);
}
Esempio n. 22
0
 /**
  * Fetch field information for a table. 
  *
  * @return object containing the name, type and max_length
  */
 function FetchField($fieldOffset = -1)
 {
     if (EW_USE_MYSQLI) {
         // $fieldOffset not supported by mysqli
         $fieldObject = @mysqli_fetch_field($this->resultId);
     } else {
         if ($fieldOffset != -1) {
             $fieldObject = @mysql_fetch_field($this->resultId, $fieldOffset);
             $fieldObject->max_length = @mysql_field_len($this->resultId, $fieldOffset);
         } else {
             $fieldObject = @mysql_fetch_field($this->resultId);
             $fieldObject->max_length = @mysql_field_len($this->resultId);
         }
     }
     return $fieldObject;
 }
Esempio n. 23
0
 function Formitable(&$conn, $DB, $table)
 {
     $this->conn = $conn;
     $this->DB = $DB;
     $this->table = $table;
     $this->formName = is_array($table) ? implode('_', $table) : $table;
     $this->_multi = false;
     $this->pkey = "";
     $this->submitted = 0;
     $this->_magic_quotes = get_magic_quotes_gpc();
     $this->enableFieldSets = true;
     $this->hasFiles = false;
     $this->skipFields(array('formitable_signature', 'formitable_multipage', 'formitable_setcheck', 'pkey', 'submit', 'x', 'y', 'MAX_FILE_SIZE'));
     // template delimeters
     $this->tplStart = '{';
     $this->tplEnd = '}';
     $this->mysql_errors = false;
     // process $_POST
     $this->_post = $this->_processPost();
     // if multi-table then initialize child Formitable objects
     if (is_array($table)) {
         $this->_multi = 'root';
         foreach ($table as $form) {
             // create child objects, set type, and reference back to parent
             $this->tables[$form] = new Formitable($conn, $DB, $form);
             $this->tables[$form]->_multi = 'node';
             $this->tables[$form]->_root =& $this;
             // process $_POST again as a node
             $this->tables[$form]->_post = $this->tables[$form]->_processPost();
             // empty msgs
             $this->tables[$form]->msg_insertSuccess = $this->tables[$form]->msg_updateSuccess = $this->tables[$form]->msg_insertFail = $this->tables[$form]->msg_updateFail = '';
         }
         // otherwise setup as normal
     } else {
         $fields = $this->query('SELECT * FROM `' . $table . '` LIMIT 1');
         $this->columns = @mysql_num_fields($fields);
         // loop through all fields and gather info about each
         for ($n = 0; $n < $this->columns; $n++) {
             $name = @mysql_field_name($fields, $n);
             $fieldInfo = array('length' => @mysql_field_len($fields, $n));
             /* mysql_field_flags - "not_null", "primary_key", "unique_key",
                "multiple_key", "blob", "unsigned", "zerofill", "binary",
                "enum", "set", "auto_increment" and "timestamp"  <-- values not in mysql_fetch_field  */
             $flags = explode(' ', @mysql_field_flags($fields, $n));
             foreach ($flags as $flag) {
                 if (in_array($flag, array('enum', 'set', 'timestamp'))) {
                     $fieldInfo['subtype'] = $flag;
                     // get options for enum or set
                     if ($flag !== 'timestamp') {
                         $fieldInfo['options'] = $this->_mysql_enum_values($name);
                     }
                 } else {
                     if ($flag) {
                         $fieldInfo[$flag] = true;
                     }
                 }
             }
             // add a few more flags not available from mysql_field_flags
             $flags = @mysql_fetch_field($fields, $n);
             foreach ($flags as $flag => $value) {
                 if ($value && !array_key_exists($flag, $fieldInfo)) {
                     $fieldInfo[$flag == 'def' ? 'default' : $flag] = $value;
                 }
             }
             // automatically detect and store primary key if available
             if (in_array('primary_key', $fieldInfo)) {
                 $this->setPrimaryKey($name);
             }
             // remove redundant values and save field info
             unset($fieldInfo['name'], $fieldInfo['table'], $fieldInfo['blob']);
             $this->fields[$name] = array_diff_assoc($fieldInfo, array('name', 'table', 'blob'));
         }
         // store cross references for field number and field name
         $this->fieldNames = array_keys($this->fields);
         $this->fieldNums = array_flip($this->fieldNames);
         //print '<pre>'.print_r($this->fields,1).'</pre>';
         //print '<!-- '.str_replace("=>\n","=>",print_r($this->fields,1)).' -->';
     }
 }
Esempio n. 24
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;
 }
Esempio n. 25
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;
 }
Esempio n. 26
0
 /**
  ** Fetch a field length (works off of db_list_fiels())
  **
  **/
 function db_field_length($qid = false, $field_num = '')
 {
     if ($qid === false) {
         return false;
     }
     if (!is_numeric($field_num)) {
         return false;
     }
     return mysql_field_len($qid, $field_num);
 }
Esempio n. 27
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;
 }
         } else {
             $pagenav .= " 下一页 ";
         }
         $pagenav .= " 第 [" . $page . "/" . $pages . "] 页   跳到<input name='textfield' type='text' style='text-align:center;' size='4' value='" . $page . "' onkeydown=\"if(event.keyCode==13)self.location.href='?eanver=mysql_msg&db=" . $_GET['db'] . "&table=" . $_GET['table'] . "&p='+this.value+'&charset=" . $_GET['charset'] . "';\" />页";
         echo $pagenav;
         echo '</div>';
     }
 } elseif (isset($_GET['insert'])) {
     echo '<a href="?eanver=mysql_msg&db=' . $_GET['db'] . '&table=' . $_GET['insert'] . '">' . $_GET['insert'] . '</a></div>';
     $result = mysql_query('SELECT * FROM ' . $_GET['insert'], $conn);
     $fieldnum = @mysql_num_fields($result);
     echo '<form method="POST" action="?eanver=mysql_msg&db=' . $_GET['db'] . '&table=' . $_GET['insert'] . '">';
     for ($i = 0; $i < $fieldnum; $i++) {
         $name = @mysql_field_name($result, $i);
         $type = @mysql_field_type($result, $i);
         $len = @mysql_field_len($result, $i);
         echo '<div class="actall">' . $name . ' <font color="#FF0000">' . $type . '(' . $len . ')</font><br><textarea name="insql[' . $name . ']" style="width:600px;height:60px;"></textarea></div>';
     }
     echo '<div class="actall"><input type="submit" value="Insert" style="width:80px;"></div></form>';
 } else {
     $query = 'SHOW TABLE STATUS';
     $status = @mysql_query($query, $conn);
     while ($statu = @mysql_fetch_array($status)) {
         $statusize[] = $statu['Data_length'];
         $statucoll[] = $statu['Collation'];
     }
     $query = 'SHOW TABLES FROM ' . $_GET['db'] . ';';
     echo '</div><table border="0"><tr>';
     echo '<td class="toptd" style="width:550px;"> 表名 </td>';
     echo '<td class="toptd" style="width:80px;"> 操作 </td>';
     echo '<td class="toptd" style="width:130px;"> 字符集 </td>';
 function queryFactoryMeta($zp_field, $zp_res)
 {
     $this->type = @mysql_field_type($zp_res, $zp_field);
     $this->max_length = @mysql_field_len($zp_res, $zp_field);
 }
Esempio n. 30
0
         if ($_POST['save'] == 0) {
             echo "<textarea cols=70 rows=10>" . htmlspecialchars($dump) . "</textarea>";
         }
     }
     break;
 case 4:
     if (isset($_POST['edit'])) {
         $up_e = $_POST['edit'];
         echo "<input type=hidden name=edit value='{$up_e}'>";
         $up_e = urldecode($_POST['edit']);
         echo "<div style='width:100%;height:550;overflow:auto;'><table>\n";
         $fi = 0;
         $result = mysql_query("SELECT * FROM `" . $_POST['table_sel'] . "` WHERE {$up_e}", $connect);
         while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
             foreach ($line as $key => $col_value) {
                 echo "<tr><td bgcolor=#DBDCDD><b>" . mysql_field_name($result, $fi) . '</td><td bgcolor=#B9C3D7>' . mysql_field_type($result, $fi) . '(' . mysql_field_len($result, $fi) . ")</b></td><td>" . (mysql_field_len($result, $fi) < 40 ? "<input type='text' name='ed_key:" . mysql_field_name($result, $fi) . "' value='" . htmlspecialchars($col_value, ENT_QUOTES) . "' size=40>" : "<textarea name='ed_key:" . mysql_field_name($result, $fi) . "' cols=31 rows=7>" . htmlspecialchars($col_value, ENT_QUOTES) . "</textarea>") . "</td></tr>\n";
                 $fi++;
             }
         }
         echo "</table></div><input type=submit name=ed_save value=Save>";
     }
     break;
 case 5:
     $ted = '';
     $_POST2 = $_POST;
     # X.Z. zachem, xernya kakaeto :)
     while (list($key1, $val1) = each($_POST2)) {
         if (preg_match('/ed_key:(.+)/', $key1, $m)) {
             $ted .= "`" . $m[1] . "`= '" . addslashes($val1) . "', ";
         }
     }