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;
}
	function query($query, $singleResult = 0) {

		$this->_result = mysql_query($query, $this->_dbHandle);
		
		
		if (preg_match("/select/i",$query)) {
		$result = array();
		$table = array();
		$field = array();
		$tempResults = array();
		$numOfFields = mysql_num_fields($this->_result);
		for ($i = 0; $i < $numOfFields; ++$i) {
		    array_push($table,mysql_field_table($this->_result, $i));
		    array_push($field,mysql_field_name($this->_result, $i));
		}
			while ($row = mysql_fetch_row($this->_result)) {
				for ($i = 0;$i < $numOfFields; ++$i) {
					$table[$i] = trim(ucfirst($table[$i]),"s");
					$tempResults[$table[$i]][$field[$i]] = $row[$i];
				}
				if ($singleResult == 1) {
		 			mysql_free_result($this->_result);
					return $tempResults;
				}
				array_push($result,$tempResults);
			}
			mysql_free_result($this->_result);
			return($result);
		}
		if(DB_DEVELOPMENT)  echo mysql_errno($this->_dbHandle),' : ',mysql_error($this->_dbHandle), '\n';
	}
 /** 自定义SQL查询语句 **/
 function query($query, $singleResult = 0)
 {
     $this->_result = mysql_query($query, $this->_dbHandle);
     if (preg_match("/select/i", $query)) {
         $result = array();
         $table = array();
         $field = array();
         $tempResults = array();
         $numOfFields = mysql_num_fields($this->_result);
         //echo $numOfFields;
         for ($i = 0; $i < $numOfFields; ++$i) {
             array_push($table, mysql_field_table($this->_result, $i));
             array_push($field, mysql_field_name($this->_result, $i));
         }
         while ($row = mysql_fetch_row($this->_result)) {
             for ($i = 0; $i < $numOfFields; ++$i) {
                 $tempResults[$table[$i]][$field[$i]] = $row[$i];
             }
             if ($singleResult == 1) {
                 mysql_free_result($this->_result);
                 return $tempResults;
             }
             array_push($result, $tempResults);
         }
         mysql_free_result($this->_result);
         //var_dump($result);
         return $result;
     }
 }
Exemple #4
0
 function query($s = '', $rows = false, $organize = true)
 {
     if (!($q = mysql_query($s, $this->con))) {
         return false;
     }
     if ($rows !== false) {
         $rows = intval($rows);
     }
     $rez = array();
     $count = 0;
     $type = $organize ? MYSQL_NUM : MYSQL_ASSOC;
     while (($rows === false || $count < $rows) && ($line = mysql_fetch_array($q, $type))) {
         if ($organize) {
             foreach ($line as $field_id => $value) {
                 $table = mysql_field_table($q, $field_id);
                 if ($table === '') {
                     $table = 0;
                 }
                 $field = mysql_field_name($q, $field_id);
                 $rez[$count][$table][$field] = $value;
             }
         } else {
             $rez[$count] = $line;
         }
         ++$count;
     }
     $this->num = $count;
     if (!mysql_free_result($q)) {
         return false;
     }
     return $rez;
 }
	/**
	 * this returns a 2d associative array with the db "table.field" name as the first element
	 *
	 * @param string $sqlTemp
	 * @return array
	 */
	function f_ReturnArrayAssoc_TF($sqlTemp) {

		$result = mysql_query ($sqlTemp);
		if(mysql_errno() != 0) {
			echo "f_ReturnArrayAssoc_TF<BR><BR>";
			echo $sqlTemp . "<BR>";
			echo "<BR><BR>" . mysql_errno() . ": " . mysql_error() . "<BR>\n";
			exit;
		}
		$intNumColumns = mysql_num_fields($result) - 1; //make zero base

		$intNumRecords = mysql_num_rows($result) - 1; //make zero base

		//Get the table-column names
		for ($i=0; $i <= $intNumColumns; $i++) {
			$arrTableFieldStructure[$i][0] = mysql_field_table($result, $i) . "." . mysql_field_name($result, $i);
		}
		if ($intNumRecords > -1) {
			//Put the data into the array
			$arrData[0][0]; //Error preventor

			$intRecord = -1; //initialize row counter
			while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
				$intRecord++; //increment the counter

				for($intColumn = 0;$intColumn <= $intNumColumns;$intColumn++){
					$arrData[$arrTableFieldStructure[$intColumn][0]][$intRecord] = $row[$intColumn];

				}
			}
			return $arrData;
		} else {
			return -1;
		}
	}
Exemple #6
0
 function getRow()
 {
     $rowData = array();
     for ($f = 0; $f < @mysql_num_fields($this->result); $f++) {
         $fieldName = @mysql_field_name($this->result, $f);
         $fieldTable = @mysql_field_table($this->result, $f);
         $rowData[$fieldTable . "." . $fieldName] = $this->row[$f];
         //htmlentities($this->row[$f]);
     }
     return $rowData;
 }
Exemple #7
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;
 }
Exemple #8
0
function mysql_fetch_table($result)
{
    if (!($row = mysql_fetch_array($result))) {
        return null;
    }
    $assoc = array();
    $rowCount = mysql_num_fields($result);
    for ($idx = 0; $idx < $rowCount; $idx++) {
        $table = mysql_field_table($result, $idx);
        $field = mysql_field_name($result, $idx);
        echo $assoc["{$table}.{$field}"] = $row[$idx] . "<BR />";
    }
    return $assoc;
}
Exemple #9
0
 function getRow()
 {
     $rowData = array();
     for ($f = 0; $f < mysql_num_fields($this->result); $f++) {
         $fieldName = mysql_field_name($this->result, $f);
         $fieldTable = mysql_field_table($this->result, $f);
         //echo $fieldName."<br>";
         //echo mb_detect_encoding($this->row[$f],"UTF-8, ISO-8859-1");
         if (!in_array(mb_detect_encoding($this->row[$f], "UTF-8, ISO-8859-1"), array("UTF-8", "ISO-8859-1"))) {
             $rowData[$fieldTable . "." . $fieldName] = mb_convert_encoding($this->row[$f], "UTF-8");
             //htmlentities($this->row[$f]);
             //echo "convirtiendo";
         } else {
             $rowData[$fieldTable . "." . $fieldName] = $this->row[$f];
             //htmlentities($this->row[$f]);
         }
         //	echo "<hr>";
     }
     return $rowData;
 }
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>";
    }
}
	/**
	 * this returns a 2d associative array with the db "table.field" name as the first element
	 *
	 * @param string $str_sql
	 * @return array
	 */
	function f_ReturnArrayAssoc_TF ($str_sql) {
		//echo $str_sql . "<BR>f_ReturnArrayAssoc_TF<HR>";
		$result = mysql_query($str_sql, $this->link);
		if(mysql_errno($this->link) != 0) {
			echo "f_ReturnArrayAssoc_TF<BR><BR>";
			echo $str_sql . "<BR>";
			echo "<BR><BR>" . mysql_errno($this->link) . ": " . mysql_error($this->link) . "<BR>\n";
			exit;
		}
		$intNumColumns = mysql_num_fields($result) - 1; //make zero base
		
		$intNumRecords = mysql_num_rows($result) - 1; //make zero base
		
		//Get the table-column names
		for ($i=0; $i <= $intNumColumns; $i++) {
			//we should probalby "strtolower()" here but there is a lot of extant code that would break
			$arrTableFieldStructure[$i][0] = mysql_field_table($result, $i) . "." . mysql_field_name($result, $i);
		}
		if ($intNumRecords > -1) {
			//Put the data into the array
			// $arrData[0][0]; //Error preventor

			$intRecord = -1; //initialize row counter
			while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
				$intRecord++; //increment the counter

				for($intColumn = 0;$intColumn <= $intNumColumns;$intColumn++){
					$arrData[$arrTableFieldStructure[$intColumn][0]][$intRecord] = $row[$intColumn];

				}
			}
			mysql_free_result($result);
			return $arrData;
		} else {
			return -1;
		}
	}
Exemple #12
0
    function print_result($RESULT) {

        if(!$RESULT) return;

        if(mysql_num_rows($RESULT) < 1) return;
        $fieldcount = mysql_num_fields($RESULT);

        for ($i=0; $i<$fieldcount; $i++) {
            $tables[mysql_field_table($RESULT, $i)]++;
        }

        print '
            <style type="text/css">
                .rs_tb_th {
                    font-family: Verdana;
                    font-size:9pt;
                    font-weight:bold;
                    color:white;
                }
                .rs_f_th {
                    font-family:Verdana;
                    font-size:7pt;
                    font-weight:bold;
                    color:white;
                }
                .rs_td {
                    font-family:Verdana;
                    font-size:7pt;
                }
            </style>
            <script type="text/javascript" language="JavaScript">
                var lastID;
                function highlight(id) {
                    if(lastID) {
                        lastID.style.color = "#000000";
                        lastID.style.textDecoration = "none";
                    }
                    tdToHighlight = document.getElementById(id);
                    tdToHighlight.style.color ="#FF0000";
                    tdToHighlight.style.textDecoration = "underline";
                    lastID = tdToHighlight;
                }
            </script>
        ';

        print '<table bgcolor="#000000" cellspacing="1" cellpadding="1">';

        print '<tr>';
        foreach ($tables as $tableName => $tableCount) {
            $col == '0054A6' ? $col = '003471' : $col = '0054A6';
            print '<th colspan="'.$tableCount.'" class="rs_tb_th" style="background-color:#'.$col.';">'.$tableName.'</th>';
        }
        print '</tr>';

        print '<tr>';
        for ($i=0;$i < mysql_num_fields($RESULT);$i++) {
            $FIELD = mysql_field_name($RESULT, $i);
            $col == '0054A6' ? $col = '003471' : $col = '0054A6';
            print '<td align="center" bgcolor="#'.$col.'" class="rs_f_th">'.$FIELD.'</td>';
        }
        print '</tr>';

        mysql_data_seek($RESULT, 0);

        while ($DB_ROW = mysql_fetch_array($RESULT, MYSQL_NUM)) {
            $pointer++;
            if($toggle) {
                $col1 = "E6E6E6";
                $col2 = "DADADA";
            } else {
                $col1 = "E1F0FF";
                $col2 = "DAE8F7";
            }
            $toggle = !$toggle;
            print '<tr id="ROW'.$pointer.'" onMouseDown="highlight(\'ROW'.$pointer.'\');">';
            foreach ($DB_ROW as $value) {
                $col == $col1 ? $col = $col2 : $col = $col1;
                print '<td valign="top" bgcolor="#'.$col.'" class="rs_td" nowrap>'.nl2br($value).'</td>';
            }
            print '</tr>';
        }
        print '</table>';
        mysql_data_seek($RESULT, 0);
    }
Exemple #13
0
 /**
  * Test mysql_field_table
  *
  * @return boolean
  */
 public function MySQL_Field_Table_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
     $table1 = mysql_field_table($query1, 0);
     $table2 = $this->_object->mysql_field_table($query2, 0);
     return $table1 === $table2;
 }
Exemple #14
0
 function mysql_fieldtable(...$args)
 {
     return mysql_field_table(...$args);
 }
Exemple #15
0
function EchoFieldsHeader($res, $numfields)
{
	$str = "";
	for( $i = 0; $i < $numfields; $i++ ) {
		$str .= GetBlock(mysql_field_name($res, $i));
		$str .= GetBlock(mysql_field_table($res, $i));

		$type = mysql_field_type($res, $i);
		$length = mysql_field_len($res, $i);
		switch ($type) {
			case "int":
				if( $length > 11 ) $type = 8;
				else $type = 3;
				break;
			case "real":
				if( $length == 12 ) $type = 4;
				elseif( $length == 22 ) $type = 5;
				else $type = 0;
				break;
			case "null":
				$type = 6;
				break;
			case "timestamp":
				$type = 7;
				break;
			case "date":
				$type = 10;
				break;
			case "time":
				$type = 11;
				break;
			case "datetime":
				$type = 12;
				break;
			case "year":
				$type = 13;
				break;
			case "blob":
				if( $length > 16777215 ) $type = 251;
				elseif( $length > 65535 ) $type = 250;
				elseif( $length > 255 ) $type = 252;
				else $type = 249;
				break;
			default:
				$type = 253;
		}
		$str .= GetLongBinary($type);

		$flags = explode( " ", mysql_field_flags ( $res, $i ) );
		$intflag = 0;
		if(in_array( "not_null", $flags )) $intflag += 1;
		if(in_array( "primary_key", $flags )) $intflag += 2;
		if(in_array( "unique_key", $flags )) $intflag += 4;
		if(in_array( "multiple_key", $flags )) $intflag += 8;
		if(in_array( "blob", $flags )) $intflag += 16;
		if(in_array( "unsigned", $flags )) $intflag += 32;
		if(in_array( "zerofill", $flags )) $intflag += 64;
		if(in_array( "binary", $flags)) $intflag += 128;
		if(in_array( "enum", $flags )) $intflag += 256;
		if(in_array( "auto_increment", $flags )) $intflag += 512;
		if(in_array( "timestamp", $flags )) $intflag += 1024;
		if(in_array( "set", $flags )) $intflag += 2048;
		$str .= GetLongBinary($intflag);

		$str .= GetLongBinary($length);
	}
	echo $str;
}
 protected function _table_name($field)
 {
     return mysql_field_table($this->_result, $field);
 }
Exemple #17
0
        $sql_query = mysql_query($sql);
        $results = mysql_num_rows($sql_query);
        $sql_result_query = mysql_query("SELECT * FROM " . $country . " WHERE (DOCUMENT_NUMBER LIKE '%" . $search_term . "%' OR DESCRIPTION LIKE '%" . $search_term . "%') LIMIT {$first_pos}, {$RESULTS_LIMIT} ");
    }
    $stop_search = getmicrotime();
    $time_search = $stop_search - $start_search;
}
while ($row = mysql_fetch_array($sql_result_query)) {
    echo "<br>";
    $dnumber = $row['DOCUMENT_NUMBER'];
    $countryto = $_GET['countryto'];
    echo $dnumber;
    echo "&nbsp;&nbsp;&nbsp;";
    echo $row['STATUS'];
    echo "&nbsp;&nbsp;&nbsp;";
    echo "Origin: " . mysql_field_table($sql_result_query, 0);
    echo "<br>";
    echo $row['DESCRIPTION'];
    echo "<br>";
    echo "<a href=" . $row['LINK'] . "> View Here</a>";
}
echo "</th></tr></table>";
echo "<br> Time taken: <br>";
echo sprintf("%01.2f", $time_search);
?>


</body>
</html>
</p>
Exemple #18
0
    function print_mysql_result($mysql_result, $return_mode = FALSE)
    {
        if (!$GLOBALS['USE_DEBUGLIB']) {
            return;
        }
        if (!$mysql_result || mysql_num_rows($mysql_result) < 1) {
            return;
        }
        $field_count = mysql_num_fields($mysql_result);
        $tables = array();
        for ($i = 0; $i < $field_count; $i++) {
            if (isset($tables[mysql_field_table($mysql_result, $i)])) {
                $tables[mysql_field_table($mysql_result, $i)]++;
            } else {
                $tables[mysql_field_table($mysql_result, $i)] = 1;
            }
        }
        $html = '
            <style type="text/css">
                table.DbugL_PR           { font-family: Verdana, Arial, Helvetica, Geneva, Swiss, SunSans-Regular, sans-serif; background:black; margin-bottom:10px; }
                table.DbugL_PR th.t_name { font-size:9pt; font-weight:bold; color:white; }
                table.DbugL_PR th.f_name { font-size:7pt; font-weight:bold; color:white; }
                table.DbugL_PR td        { padding-left:2px;font-size:7pt; white-space:nowrap; vertical-align:top; }
            </style>
            <script type="text/javascript">
                //<![CDATA[

                var DbugL_last_id;
                function DbugL_highlight(id) {
                    if(DbugL_last_id) {
                        DbugL_last_id.style.color = "#000000";
                        DbugL_last_id.style.textDecoration = "none";
                    }
                    var highlight_td;
                    highlight_td = document.getElementById(id);
                    highlight_td.style.color ="#FF0000";
                    highlight_td.style.textDecoration = "underline";
                    DbugL_last_id = highlight_td;
                }

                //]]>
            </script>
        ';
        $html .= '<table class="DbugL_PR" cellspacing="1" cellpadding="1">';
        $html .= '<tr>';
        foreach ($tables as $tableName => $tableCount) {
            !isset($col) || $col == '#006F05' ? $col = '#00A607' : ($col = '#006F05');
            $html .= '<th colspan="' . $tableCount . '" class="t_name" style="background:' . $col . ';">' . $tableName . '</th>';
        }
        $html .= '</tr>';
        $html .= '<tr>';
        for ($i = 0; $i < mysql_num_fields($mysql_result); $i++) {
            $field = mysql_field_name($mysql_result, $i);
            $col == '#0054A6' ? $col = '#003471' : ($col = '#0054A6');
            $html .= '<th style="background:' . $col . ';" class="f_name">' . $field . '</th>';
        }
        $html .= '</tr>';
        mysql_data_seek($mysql_result, 0);
        $toggle = FALSE;
        $pointer = 0;
        $table_id = str_replace('.', '', microtime(TRUE));
        while ($db_row = mysql_fetch_array($mysql_result, MYSQL_NUM)) {
            $pointer++;
            if ($toggle) {
                $col1 = "#E6E6E6";
                $col2 = "#DADADA";
            } else {
                $col1 = "#E1F0FF";
                $col2 = "#DAE8F7";
            }
            $toggle = !$toggle;
            $id = 'DbugL_' . $table_id . '_' . $pointer;
            $html .= '<tr id="' . $id . '" onMouseDown="DbugL_highlight(\'' . $id . '\');">';
            foreach ($db_row as $i => $value) {
                $col == $col1 ? $col = $col2 : ($col = $col1);
                $flags = mysql_field_flags($mysql_result, $i);
                $primary_flag = strpos($flags, 'primary_key') !== FALSE;
                $html .= '<td style="background:' . $col . ';' . ($primary_flag ? 'font-weight:bold;' : '') . '" nowrap="nowrap">' . nl2br($value) . '</td>';
            }
            $html .= '</tr>';
        }
        $html .= '</table>';
        mysql_data_seek($mysql_result, 0);
        if ($return_mode) {
            return $html;
        } else {
            print $html;
        }
    }
 public function table_info($table)
 {
     if ($table) {
         $this->result = mysql_query("select * from {$table}");
         $this->query = "select * from {$table}";
         $fields = mysql_num_fields($this->result);
         $rows = mysql_num_rows($this->result);
         $table = mysql_field_table($this->result, 0);
         print "\tThe '<strong>" . $table . "</strong>' table has <strong>" . $fields . "</strong> fields and <strong>" . $rows . "</strong>\n\t\t\t\t\t\trecord(s) with following fields.\n<br /><ul>";
         for ($i = 0; $i < $fields; $i++) {
             $type = mysql_field_type($this->result, $i);
             $name = mysql_field_name($this->result, $i);
             $len = mysql_field_len($this->result, $i);
             $flags = mysql_field_flags($this->result, $i);
             print "<strong><li>" . $type . " " . $name . " " . $len . " " . $flags . "</strong></li>\n";
         }
         print "</ul>";
     } else {
         print "The table not specified !!";
     }
 }
Exemple #20
0
<title></title>
</head>

<body bgcolor="#FFFFCC" text="#000000" link="#006600" vlink="#993333" alink="#CC6600" background="rlaemb.JPG">

<?php 
$priviledge = '00';
include 'allow_to_show.inc';
$dbcont = "invalid";
include "connet_root.inc";
mysql_select_db("timesheet");
$result = mysql_query("SELECT * FROM iplist");
$fields = mysql_num_fields($result);
$rows = mysql_num_rows($result);
$i = 0;
$table = mysql_field_table($result, $i);
echo "<b>Table '" . $table . "' has " . $fields . " fields and " . $rows . " records.<br><br></b>";
echo '<br><font size="2" color="#0000FF"><b>Records are:</b></font><BR>';
echo "<table border=\"1\">";
echo "<tr>";
$i = 0;
while ($i < $fields) {
    $name = mysql_field_name($result, $i);
    printf("<td>%s</td>", $name);
    $i++;
}
echo "</tr>";
while ($myrow = mysql_fetch_array($result)) {
    echo "<tr>";
    $i = 0;
    $i = (int) 1.5;
Exemple #21
0
 function tableInfo($result, $mode = null)
 {
     $count = 0;
     $id = 0;
     $res = array();
     /*
      * depending on $mode, metadata returns the following values:
      *
      * - mode is null (default):
      * $result[]:
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *
      * - mode is DB_TABLEINFO_ORDER
      * $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
      *   ["order"][field name]  index of field named "field name"
      *   The last one is used, if you have a field name, but no index.
      *   Test:  if (isset($result['meta']['myfield'])) { ...
      *
      * - mode is DB_TABLEINFO_ORDERTABLE
      *    the same as above. but additionally
      *   ["ordertable"][table name][field name] index of field
      *      named "field name"
      *
      *      this is, because if you have fields from different
      *      tables with the same field name * they override each
      *      other with DB_TABLEINFO_ORDER
      *
      *      you can combine DB_TABLEINFO_ORDER and
      *      DB_TABLEINFO_ORDERTABLE with DB_TABLEINFO_ORDER |
      *      DB_TABLEINFO_ORDERTABLE * or with DB_TABLEINFO_FULL
      */
     // if $result is a string, then we want information about a
     // table without a resultset
     if (is_string($result)) {
         $id = @mysql_list_fields($this->dsn['database'], $result, $this->connection);
         if (empty($id)) {
             return $this->mysqlRaiseError();
         }
     } else {
         // else we want information about a resultset
         $id = $result;
         if (empty($id)) {
             return $this->mysqlRaiseError();
         }
     }
     $count = @mysql_num_fields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (empty($mode)) {
         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);
             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 (is_string($result)) {
         @mysql_free_result($id);
     }
     return $res;
 }
 /**
  * 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;
 }
 /** Custom SQL Query **/
 function custom($query)
 {
     global $inflect;
     $this->_result = mysql_query($query, $this->_dbHandle);
     $result = array();
     $table = array();
     $field = array();
     $tempResults = array();
     if (substr_count(strtoupper($query), "SELECT") > 0) {
         if (mysql_num_rows($this->_result) > 0) {
             $numOfFields = mysql_num_fields($this->_result);
             for ($i = 0; $i < $numOfFields; ++$i) {
                 array_push($table, mysql_field_table($this->_result, $i));
                 array_push($field, mysql_field_name($this->_result, $i));
             }
             while ($row = mysql_fetch_row($this->_result)) {
                 for ($i = 0; $i < $numOfFields; ++$i) {
                     $table[$i] = ucfirst($inflect->singularize($table[$i]));
                     $tempResults[$table[$i]][$field[$i]] = $row[$i];
                 }
                 array_push($result, $tempResults);
             }
         }
         mysql_free_result($this->_result);
     }
     $this->clear();
     return $result;
 }
Exemple #24
0
 function metadata($table)
 {
     $count = 0;
     $id = 0;
     $res = array();
     $this->connect();
     $id = @mysql_list_fields($this->Database, $table);
     if ($id < 0) {
         $this->Errno = mysql_errno();
         $this->Error = mysql_error();
         $this->halt("Metadata query failed.");
     }
     $count = mysql_num_fields($id);
     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;
         $res["num_fields"] = $count;
     }
     mysql_free_result($id);
     return $res;
 }
				function	setQueryString($sql)
					{
							$this->sql = $sql;
							$this->numOfFields	=	$this->fieldList($this->fieldName,$this->sql,$this->res);	
							$this->tabelName	=	mysql_field_table($this->res,$this->fieldName[0]);
						
					}
Exemple #26
0
 /**
  * return table metadata.
  * If no $table specified, assume that we are working with a query result.
  * 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'])) { ...
  *
  * @param string $table the database table to analyze
  * @param bool $full set the output type (see description)
  */
 public function metadata($table = "", $full = false)
 {
     $count = 0;
     $id = 0;
     $res = array();
     // if no $table specified, assume that we are working with a query result
     if ($table) {
         $this->connect();
         $id = @mysql_list_fields(self::$config["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);
     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);
     }
     return $res;
 }
 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;
 }
 /**
  * returns metainfo for fields in $result
  *
  * @param resource $result MySQL result
  *
  * @return array meta info for fields in $result
  *
  * @todo add missing keys like in mysqli_query (decimals)
  */
 public function getFieldsMeta($result)
 {
     $fields = array();
     $num_fields = mysql_num_fields($result);
     for ($i = 0; $i < $num_fields; $i++) {
         $field = mysql_fetch_field($result, $i);
         $field->flags = mysql_field_flags($result, $i);
         $field->orgtable = mysql_field_table($result, $i);
         $field->orgname = mysql_field_name($result, $i);
         $fields[] = $field;
     }
     return $fields;
 }
Exemple #29
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;
 }
 /**
  * Show table meta data.
  *
  * @param    string  table       Table to show. If false, use query result.
  */
 public function metadata($table = false)
 {
     // Connect if not already
     $this->connect();
     // Init
     $count = 0;
     $id = 0;
     $result = array();
     // From table
     if ($table) {
         $id = @mysql_list_fields($this->database, $table);
         if (!$id) {
             return $this->fail("Metadata query failed.");
         }
     } else {
         $id = $this->cursor;
         if (!$id) {
             return $this->fail("No query specified.");
         }
     }
     $count = @mysql_num_fields($id);
     // Build result
     for ($i = 0; $i < $count; $i++) {
         $result[$i]["table"] = @mysql_field_table($id, $i);
         $result[$i]["name"] = @mysql_field_name($id, $i);
         $result[$i]["type"] = @mysql_field_type($id, $i);
         $result[$i]["len"] = @mysql_field_len($id, $i);
         $result[$i]["flags"] = @mysql_field_flags($id, $i);
     }
     // Free the if we were called on a table
     if ($table) {
         @mysql_free_result($id);
     }
     // Return
     return $result;
 }