本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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";
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}