當前位置: 首頁>>代碼示例>>PHP>>正文


PHP mysqli_fetch_fields函數代碼示例

本文整理匯總了PHP中mysqli_fetch_fields函數的典型用法代碼示例。如果您正苦於以下問題:PHP mysqli_fetch_fields函數的具體用法?PHP mysqli_fetch_fields怎麽用?PHP mysqli_fetch_fields使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了mysqli_fetch_fields函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: cast_query_results

 public static function cast_query_results($rs)
 {
     $fields = mysqli_fetch_fields($rs);
     $data = array();
     $types = array();
     foreach ($fields as $field) {
         switch ($field->type) {
             case 1:
                 $types[$field->name] = 'boolean';
                 break;
             case 3:
                 $types[$field->name] = 'int';
                 break;
             case 4:
                 $types[$field->name] = 'float';
                 break;
             default:
                 $types[$field->name] = 'string';
                 break;
         }
     }
     while ($row = mysqli_fetch_assoc($rs)) {
         $data[] = $row;
     }
     for ($i = 0; $i < count($data); $i++) {
         foreach ($types as $name => $type) {
             settype($data[$i][$name], $type);
         }
     }
     return $data;
 }
開發者ID:StockersSRL,項目名稱:Lucas,代碼行數:31,代碼來源:clases+-+Copy.php

示例2: fetch_next

 function fetch_next($class = null)
 {
     $fetch = $this->fetch_type;
     $result = $this->result;
     switch ($fetch) {
         case MySqliResult::$FETCH_OBJECT:
             if ($class != null) {
                 $row = $result->fetch_object($class, null);
             } else {
                 $row = $result->fetch_object();
             }
             //mysqli_fetch_object($result);
             break;
         case MySqliResult::$FETCH_ARRAY:
             $row = mysqli_fetch_array($result);
             break;
         case MySqliResult::$FETCH_FIELDS:
             $row = mysqli_fetch_fields($result);
             break;
         case MySqliResult::$FETCH_LENGTHS:
             $row = mysqli_fetch_fields($result);
             break;
         case MySqliResult::$FETCH_ROW:
             $row = mysqli_fetch_row($result);
             break;
         case MySqliResult::$FETCH_ASSOC:
             $row = mysqli_fetch_assoc($result);
             break;
     }
     return $row;
 }
開發者ID:htmlgraphic,項目名稱:HTMLgraphic-MVC,代碼行數:31,代碼來源:MySqliResult.class.inc.php

示例3: mysql_query_cache

function mysql_query_cache($sql, $linkIdentifier = false, $timeout = 4)
{
    $mysqli = $GLOBALS['mysqli'];
    //首先調用上麵的getCache函數,如果返回值不為false的話,就說明是從memcached服務器獲取的數據
    //如果返回false,此時就需要直接從數據庫中獲取數據了。
    //需要注意的是這裏使用操作的命令加上sql語句的md5碼作為一個特定的key,可能大家覺得使用數據項的
    //名稱作為key會比較自然一點。運行memcached加上"-vv"參數,並且不作為daemon運行的話,可以看見
    //memcached處理時輸出的相關信息
    if (!($cache = getCache(md5("mysql_query" . $sql)))) {
        $cache = false;
        $r = mysqli_query($mysqli, $sql);
        $fields = mysqli_fetch_fields($r);
        //讀取數據庫,並將結果放入$cache數組中
        for ($i = 0; $row = mysqli_fetch_array($r); $i++) {
            $j = 0;
            foreach ($fields as $val) {
                $cache[$i][$val->name] = $row[$j];
                $j++;
            }
        }
        //將數據放入memcached服務器中,如果memcached服務器沒有開的話,此語句什麽也不會做
        //如果開啟了服務器的話,數據將會被緩存到memcached服務器中
        if (!setCache(md5("mysql_query" . $sql), $cache, $timeout)) {
            # If we get here, there isn’t a memcache daemon running or responding
            echo "apt-get install memcached";
        }
    }
    return $cache;
}
開發者ID:RX78NY1,項目名稱:hustoj,代碼行數:29,代碼來源:memcache.php

示例4: display_data_in_table

 public function display_data_in_table($sql)
 {
     $this->last_query = $sql;
     $result = mysqli_query($this->db, $sql);
     if (mysqli_num_rows($result) > 0) {
         $finfo = mysqli_fetch_fields($result);
         echo "<table class='table'>";
         echo "<tr>";
         foreach ($finfo as $val) {
             echo "<td>";
             $self = $_SERVER['PHP_SELF'];
             echo "<b>" . $val->name . "<b></a>";
             echo "</td>";
         }
         echo "<td><b>custom</b></td>";
         echo "</tr>";
         while ($row = mysqli_fetch_array($result)) {
             echo "<tr>";
             for ($x = 0; $x < count($finfo); $x++) {
                 echo "<td>";
                 echo $row[$x];
                 echo "</td>";
             }
             echo "<td><a href='#'><button>custom</button></a></td>";
             echo "</tr>";
         }
         // end of while
         echo "</table>";
         // echo "<input type='submit' value='delete'>";
         echo "</form>";
     } else {
         echo "0 results";
     }
 }
開發者ID:KenProchnow,項目名稱:ExpenseApp,代碼行數:34,代碼來源:database.php

示例5: fetch

 /**
  * 獲取結果集
  **/
 public function fetch($rs, $fetchMode = self::DB_FETCH_DEFAULT)
 {
     $fields = mysqli_fetch_fields($rs);
     $values = mysqli_fetch_array($rs, $fetchMode);
     if ($values) {
         foreach ($fields as $field) {
             switch ($field->type) {
                 case MYSQLI_TYPE_TINY:
                 case MYSQLI_TYPE_SHORT:
                 case MYSQLI_TYPE_INT24:
                 case MYSQLI_TYPE_LONG:
                     if ($field->type == MYSQLI_TYPE_TINY && $field->length == 1) {
                         $values[$field->name] = (bool) $values[$field->name];
                     } else {
                         $values[$field->name] = (int) $values[$field->name];
                     }
                     break;
                 case MYSQLI_TYPE_DECLIMAL:
                 case MYSQLI_TYPE_FLOAT:
                 case MYSQLI_TYPE_DOUBLE:
                 case MYSQLI_TYPE_LONGLONG:
                     $values[$field->name] = (double) $values[$field->name];
                     break;
             }
         }
     }
     return $values;
 }
開發者ID:hsiun,項目名稱:laputa,代碼行數:31,代碼來源:MysqliDb.php

示例6: field_data

 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @access	public
  * @return	array
  */
 function field_data()
 {
     $retval = array();
     $field_data = mysqli_fetch_fields($this->result_id);
     for ($i = 0, $c = count($field_data); $i < $c; $i++) {
         $retval[$i] = new stdClass();
         $retval[$i]->name = $field_data[$i]->name;
         $retval[$i]->type = $field_data[$i]->type;
         $retval[$i]->max_length = $field_data[$i]->max_length;
         $retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
         $retval[$i]->default = '';
     }
     /** Fixed from github commit. See https://github.com/EllisLab/CodeIgniter/commit/effd0133b3fa805e21ec934196e8e7d75608ba00
     		while ($field = mysqli_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;
 }
開發者ID:jaksmid,項目名稱:website,代碼行數:40,代碼來源:mysqli_result.php

示例7: old_mysql_result

/**
 * Fonction basée sur l'api mysqli et
 * simulant la fonction mysql_result()
 * Copyright 2014 Marc Leygnac
 *
 * @param type $result résultat après requête
 * @param integer $row numéro de la ligne
 * @param string/integer $field indice ou nom du champ
 * @return type valeur du champ ou false si erreur
 */
function old_mysql_result($result, $row, $field = 0)
{
    if ($result === false) {
        return false;
    }
    if ($row >= mysqli_num_rows($result)) {
        return false;
    }
    if (is_string($field) && !(strpos($field, ".") === false)) {
        // si $field est de la forme table.field ou alias.field
        // on convertit $field en indice numérique
        $t_field = explode(".", $field);
        $field = -1;
        $t_fields = mysqli_fetch_fields($result);
        for ($id = 0; $id < mysqli_num_fields($result); $id++) {
            if ($t_fields[$id]->table == $t_field[0] && $t_fields[$id]->name == $t_field[1]) {
                $field = $id;
                break;
            }
        }
        if ($field == -1) {
            return false;
        }
    }
    mysqli_data_seek($result, $row);
    $line = mysqli_fetch_array($result);
    return isset($line[$field]) ? $line[$field] : false;
}
開發者ID:rhertzog,項目名稱:lcs,代碼行數:38,代碼來源:old_mysql_result.php

示例8: fetch_fields

 /**
  * Return rows of field information in a result set. This function is a
  * basically a wrapper on the native mysqli_fetch_fields function.
  *
  * @param bool $as_array Return each field info as array; defaults to false
  *
  * @return array Array of field information each as an associative array
  */
 public function fetch_fields($as_array = false)
 {
     if ($as_array) {
         return array_map(function ($object) {
             return (array) $object;
         }, mysqli_fetch_fields($this->result));
     } else {
         return mysqli_fetch_fields($this->result);
     }
 }
開發者ID:nramenta,項目名稱:dabble,代碼行數:18,代碼來源:Result.php

示例9: getResgitro

 public function getResgitro($rsQuery, $iLinha)
 {
     $oStdClas = new stdClass();
     $aResult = mysqli_fetch_row($rsQuery);
     if ($aResult != null) {
         $aCampos = mysqli_fetch_fields($rsQuery);
         foreach ($aCampos as $iCampo => $aCampo) {
             $oStdClas->{$aCampo->name} = $aResult[$iCampo];
         }
     }
     return $oStdClas;
 }
開發者ID:ricardosander,項目名稱:petshop,代碼行數:12,代碼來源:MySQL.php

示例10: func_mysqli_fetch_array

function func_mysqli_fetch_array($mysqli, $engine, $sql_type, $sql_value, $php_value, $offset, $regexp_comparison = NULL)
{
    if (!$mysqli->query("DROP TABLE IF EXISTS test")) {
        printf("[%04d] [%d] %s\n", $offset, $mysqli->errno, $mysqli->error);
        return false;
    }
    if (!$mysqli->query($sql = sprintf("CREATE TABLE test(id INT NOT NULL, label %s, PRIMARY KEY(id)) ENGINE = %s", $sql_type, $engine))) {
        // don't bail, engine might not support the datatype
        return false;
    }
    if (is_null($php_value)) {
        if (!$mysqli->query($sql = sprintf("INSERT INTO test(id, label) VALUES (1, NULL)"))) {
            printf("[%04d] [%d] %s\n", $offset + 1, $mysqli->errno, $mysqli->error);
            return false;
        }
    } else {
        if (is_string($sql_value)) {
            if (!$mysqli->query($sql = "INSERT INTO test(id, label) VALUES (1, '" . $sql_value . "')")) {
                printf("[%04ds] [%d] %s - %s\n", $offset + 1, $mysqli->errno, $mysqli->error, $sql);
                return false;
            }
        } else {
            if (!$mysqli->query($sql = sprintf("INSERT INTO test(id, label) VALUES (1, '%d')", $sql_value))) {
                printf("[%04di] [%d] %s\n", $offset + 1, $mysqli->errno, $mysqli->error);
                return false;
            }
        }
    }
    if (!($res = $mysqli->query("SELECT id, label FROM test"))) {
        printf("[%04d] [%d] %s\n", $offset + 2, $mysqli->errno, $mysqli->error);
        return false;
    }
    if (!($row = $res->fetch_array(MYSQLI_BOTH))) {
        printf("[%04d] [%d] %s\n", $offset + 3, $mysqli->errno, $mysqli->error);
        return false;
    }
    $fields = mysqli_fetch_fields($res);
    if (!(gettype($php_value) == "unicode" && $fields[1]->flags & 128)) {
        if ($regexp_comparison) {
            if (!preg_match($regexp_comparison, (string) $row['label']) || !preg_match($regexp_comparison, (string) $row[1])) {
                printf("[%04d] Expecting %s/%s [reg exp = %s], got %s/%s resp. %s/%s. [%d] %s\n", $offset + 4, gettype($php_value), $php_value, $regexp_comparison, gettype($row[1]), $row[1], gettype($row['label']), $row['label'], $mysqli->errno, $mysqli->error);
                return false;
            }
        } else {
            if ($row['label'] !== $php_value || $row[1] != $php_value) {
                printf("[%04d] Expecting %s/%s, got %s/%s resp. %s/%s. [%d] %s\n", $offset + 4, gettype($php_value), $php_value, gettype($row[1]), $row[1], gettype($row['label']), $row['label'], $mysqli->errno, $mysqli->error);
                return false;
            }
        }
    }
    return true;
}
開發者ID:gleamingthecube,項目名稱:php,代碼行數:52,代碼來源:ext_mysqli_tests_mysqli_fetch_array_oo.php

示例11: _performGetBlobFieldNames

 protected function _performGetBlobFieldNames($result)
 {
     $allFields = mysqli_fetch_fields($result);
     $blobFields = array();
     if (!empty($allFields)) {
         foreach ($allFields as $field) {
             if (stripos($field["type"], "BLOB") !== false) {
                 $blobFields[] = $field["name"];
             }
         }
     }
     return $blobFields;
 }
開發者ID:KaMaToZzz,項目名稱:livestreet-framework,代碼行數:13,代碼來源:Mysqli.php

示例12: __construct

 public function __construct($qvar)
 {
     //constructor takes query string as a parameter
     include "/home/ubuntu/workspace/db_connect.php";
     //contains $conn - Oracle connection info
     $this->qvar = $qvar;
     $sql = $mysqli->query($this->qvar);
     $this->numcols = mysqli_num_fields($sql);
     $this->colname = mysqli_fetch_fields($sql);
     $this->numrows = mysqli_num_rows($sql);
     while ($row = mysqli_fetch_assoc($sql)) {
         $this->tableArray[] = $row;
     }
     $sql->close();
 }
開發者ID:bushwald,項目名稱:pizza,代碼行數:15,代碼來源:MySqlArray.php

示例13: zerofill

function zerofill($offset, $link, $datatype, $insert = 1)
{
    mysqli_query($link, 'ALTER TABLE test_mysqli_stmt_bind_result_zerofill_table_1 DROP zero');
    $sql = sprintf('ALTER TABLE test_mysqli_stmt_bind_result_zerofill_table_1 ADD zero %s UNSIGNED ZEROFILL', $datatype);
    if (!mysqli_query($link, $sql)) {
        // no worries - server might not support it
        return true;
    }
    if (!mysqli_query($link, sprintf('UPDATE test_mysqli_stmt_bind_result_zerofill_table_1 SET zero = %s', $insert))) {
        printf("[%03d] UPDATE failed, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!($stmt = mysqli_prepare($link, 'SELECT zero FROM test_mysqli_stmt_bind_result_zerofill_table_1 LIMIT 1'))) {
        printf("[%03d] SELECT failed, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    $result = null;
    if (!mysqli_stmt_bind_result($stmt, $result)) {
        printf("[%03d] Bind failed, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        return false;
    }
    if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt)) {
        printf("[%03d] Execute or fetch failed, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        return false;
    }
    $res = mysqli_stmt_result_metadata($stmt);
    $meta = mysqli_fetch_fields($res);
    mysqli_stmt_free_result($stmt);
    $meta = $meta[0];
    $length = $meta->length;
    if ($length > strlen($insert)) {
        $expected = str_repeat('0', $length - strlen($insert));
        $expected .= $insert;
        if ($expected !== $result) {
            printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $result);
            return false;
        }
    } else {
        if ($length <= 1) {
            printf("[%03d] Length reported is too small to run test\n", $offset);
            return false;
        }
    }
    return true;
}
開發者ID:alphaxxl,項目名稱:hhvm,代碼行數:45,代碼來源:mysqli_stmt_bind_result_zerofill.php

示例14: attributes

 protected function attributes()
 {
     // return an array of attribute keys and there values
     global $database;
     //$row_result = $database->query("select * from ". static::$table_name. " where id=1 limit 1");
     $row_result = $database->query("select * from " . static::$table_name . " limit 1");
     $finfo = mysqli_fetch_fields($row_result);
     //echo "attributes are: ". print_r($finfo);
     $attribute = array();
     foreach ($finfo as $val) {
         $name = $val->name;
         if (property_exists($this, $name)) {
             $attribute["{$name}"] = $this->{$name};
             //"'$"."{$name}'";
         }
     }
     mysqli_free_result($row_result);
     return $attribute;
 }
開發者ID:RichJones22,項目名稱:photo_gallery,代碼行數:19,代碼來源:database_object.php

示例15: build_cbm_tables

function build_cbm_tables()
{
    $tables = array();
    $mysqli = mysqli_connect("localhost", "root", "", "cbm");
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\r\n", mysqli_connect_error());
        exit;
    }
    //查找所有的表名
    $result = $mysqli->query("show tables");
    //執行查詢語句
    while ($arr = $result->fetch_assoc()) {
        $tbl = $arr["Tables_in_cbm"];
        //遍曆查詢結果
        if ($tbl == 'cbm_dummy') {
            continue;
        }
        $tables[$tbl] = array();
    }
    //查找表中的所有字段
    foreach (array_keys($tables) as $tbl) {
        $query = "SELECT * from {$tbl}";
        if ($result = mysqli_query($mysqli, $query)) {
            /* Get field information for all columns */
            $finfo = mysqli_fetch_fields($result);
            $fields = array();
            foreach ($finfo as $val) {
                //類型編號映射成c++數據類型
                // var_dump($tbl.'----'.h_type2txt($val->type));
                $fields[$val->name] = MYSQL_type_to_cpp_type(h_type2txt($val->type));
            }
            $tables[$tbl] = $fields;
            mysqli_free_result($result);
        }
    }
    /* close connection */
    mysqli_close($mysqli);
    return $tables;
}
開發者ID:hunanhd,項目名稱:cbm,代碼行數:40,代碼來源:index.php


注:本文中的mysqli_fetch_fields函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。