当前位置: 首页>>代码示例>>PHP>>正文


PHP mysqli_stmt_result_metadata函数代码示例

本文整理汇总了PHP中mysqli_stmt_result_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_stmt_result_metadata函数的具体用法?PHP mysqli_stmt_result_metadata怎么用?PHP mysqli_stmt_result_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mysqli_stmt_result_metadata函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: iimysqli_stmt_get_result

 public static function iimysqli_stmt_get_result($stmt)
 {
     /**    EXPLANATION:
      * We are creating a fake "result" structure to enable us to have
      * source-level equivalent syntax to a query executed via
      * mysqli_query().
      *
      *    $stmt = mysqli_prepare($conn, "");
      *    mysqli_bind_param($stmt, "types", ...);
      *
      *    $param1 = 0;
      *    $param2 = 'foo';
      *    $param3 = 'bar';
      *    mysqli_execute($stmt);
      *    $result _mysqli_stmt_get_result($stmt);
      *        [ $arr = _mysqli_result_fetch_array($result);
      *            || $assoc = _mysqli_result_fetch_assoc($result); ]
      *    mysqli_stmt_close($stmt);
      *    mysqli_close($conn);
      *
      * At the source level, there is no difference between this and mysqlnd.
      **/
     $metadata = mysqli_stmt_result_metadata($stmt);
     $ret = new iimysqli_result();
     if (!$ret) {
         return NULL;
     }
     $ret->nCols = mysqli_num_fields($metadata);
     $ret->columns = $metadata->fetch_fields();
     $ret->stmt = $stmt;
     mysqli_free_result($metadata);
     return $ret;
 }
开发者ID:senioroman4uk,项目名称:Simple-PHP-MVC,代码行数:33,代码来源:iimysqli_result.php

示例2: stmtRowAssoc

 /**
  * Возвращяет строку в виде ассоциативного массива
  * @param  stmt Запрос
  * @return array
  */
 private function stmtRowAssoc($stmt)
 {
     if ($stmt instanceof \mysqli_stmt) {
         $data = mysqli_stmt_result_metadata($stmt);
         if (false !== $data) {
             $args = [$stmt];
             $field = [];
             while ($f = $data->fetch_field()) {
                 $f = $f->name;
                 $field[$f] = $f;
                 $args[] =& $field[$f];
             }
             call_user_func_array(mysqli_stmt_bind_result, $args);
             if ($stmt->fetch()) {
                 return $field;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
开发者ID:sete-pw,项目名称:images,代码行数:30,代码来源:SQLi.php

示例3: stmt_assoc

 private function stmt_assoc(&$stmt, array &$out)
 {
     $data = mysqli_stmt_result_metadata($stmt);
     $fields = array($this->_STMT);
     $out = array();
     while ($field = mysqli_fetch_field($data)) {
         $fields[] =& $out[$field->name];
     }
     call_user_func_array('mysqli_stmt_bind_result', $fields);
 }
开发者ID:habb0,项目名称:SulakeWeb,代码行数:10,代码来源:DataObject.MySQLi.php

示例4: stmt_bind_assoc

function stmt_bind_assoc(&$stmt, &$out)
{
    $data = mysqli_stmt_result_metadata($stmt);
    $fields = array();
    $out = array();
    $fields[0] = $stmt;
    $count = 1;
    while ($field = mysqli_fetch_field($data)) {
        $fields[$count] =& $out[$field->name];
        $count++;
    }
    call_user_func_array(mysqli_stmt_bind_result, $fields);
}
开发者ID:jonca44,项目名称:pdf-mailmerge,代码行数:13,代码来源:reactivate_account.php

示例5: 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

示例6: __construct

 public function __construct($res, $connection)
 {
     $this->res = $res;
     $this->connection = $connection;
     $this->meta = \mysqli_stmt_result_metadata($this->res);
     if (!$this->meta) {
         //occurs on insert
         //throw new \Exception("Could not retrieve meta for prepare statement");}
         return;
     }
     while ($field = $this->meta->fetch_field()) {
         $this->binds[$field->table . '.' . $field->name] =& $this->binds[$field->table . '.' . $field->name];
     }
     //fix for ambiguous fieldnames
     \mysqli_free_result($this->meta);
     call_user_func_array(array($this->res, 'bind_result'), $this->binds);
     //you need 2 append the parameters - thats the right way to do that.
     $this->res->store_result();
 }
开发者ID:webcraftmedia,项目名称:system,代码行数:19,代码来源:ResultMysqliPrepare.php

示例7: stmt_bind_assoc

function stmt_bind_assoc(&$stmt, &$out)
{
    $data = mysqli_stmt_result_metadata($stmt);
    $fields = array();
    $out = array();
    $fields[0] = $stmt;
    for ($i = 1; $field = mysqli_fetch_field($data); $i++) {
        $fields[$i] =& $out[$field->name];
    }
    call_user_func_array('mysqli_stmt_bind_result', $fields);
}
开发者ID:HomerGaidarski,项目名称:Gunter-Hans-Transaction-Reports,代码行数:11,代码来源:graphs.php

示例8: execSQL

function execSQL($query, $params, $close)
{
    global $error_message;
    global $conn;
    // LOG
    LOG_MSG('DEBUG', "execSQL(): START");
    LOG_MSG('DEBUG', " QUERY=[" . $query . "]");
    LOG_MSG('DEBUG', " PARAMS\n[" . print_r($params, true) . "]");
    $log_query = preg_replace("/\t/", " ", $query);
    $log_query = preg_replace("/\n/", " ", $log_query);
    $log_query = preg_replace("/[\\s]+/", " ", $log_query);
    LOG_MSG('INFO', " QUERY=[{$log_query}] PARAMS=[" . implode("|", $params) . "]");
    // Reset result set before starting
    $resp = array("STATUS" => "ERROR");
    // For DMLs
    $resp[0]['STATUS'] = "ERROR";
    // For Selects
    $error_message = "There was an error proccessing your request. Please check and try again";
    // INIT STATEMENT
    if (!($stmt = mysqli_stmt_init($conn))) {
        LOG_MSG('ERROR', "execSQL(): Error initializing statement: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "]. ");
        $resp['SQL_ERROR_CODE'] = mysqli_errno($conn);
        return $resp;
    }
    LOG_MSG('DEBUG', "execSQL():\t Init query");
    // PREPARE
    if (!mysqli_stmt_prepare($stmt, $query)) {
        LOG_MSG('ERROR', "execSQL(): Error preparing statement: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "].");
        $resp['SQL_ERROR_CODE'] = mysqli_errno($conn);
        return $resp;
    }
    LOG_MSG('DEBUG', "execSQL():\t Prepared query");
    // BIND PARAMS
    if (!empty($params)) {
        // Bind input params
        if (!call_user_func_array(array($stmt, 'bind_param'), refValues($params))) {
            LOG_MSG('ERROR', "execSQL(): Error binding input params: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "].");
            $resp['SQL_ERROR_CODE'] = mysqli_errno($conn);
            mysqli_stmt_close($stmt);
            // Close statement
            return $resp;
        }
    }
    LOG_MSG('DEBUG', "execSQL():\t Bound query parameters");
    // EXECUTE
    $qry_exec_time = microtime(true);
    $status = mysqli_stmt_execute($stmt);
    $qry_exec_time = number_format(microtime(true) - $qry_exec_time, 4);
    if (!$status) {
        LOG_MSG('ERROR', "execSQL(): Error executing statement: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "].");
        $resp['SQL_ERROR_CODE'] = mysqli_errno($conn);
        mysqli_stmt_close($stmt);
        // Close statement
        return $resp;
    }
    LOG_MSG('INFO', "      Executed query in {$qry_exec_time} secs");
    // DMLs (insert/update/delete)
    // If CLOSE, then return no of rows affected
    if ($close) {
        unset($resp[0]);
        $error_message = "";
        $resp["STATUS"] = "OK";
        $resp["EXECUTE_STATUS"] = $status;
        $resp["NROWS"] = $conn->affected_rows;
        $resp["INSERT_ID"] = $conn->insert_id;
        mysqli_stmt_close($stmt);
        // Close statement
        LOG_MSG('INFO', "      Status=[OK] Affected rows [" . $resp['NROWS'] . "]");
        LOG_MSG('DEBUG', "execSQL(): UPDATE/INSERT response:\n[" . print_r($resp, true) . "]");
        LOG_MSG('DEBUG', "execSQL(): END");
        return $resp;
    }
    // SELECT
    $result_set = mysqli_stmt_result_metadata($stmt);
    while ($field = mysqli_fetch_field($result_set)) {
        $parameters[] =& $row[$field->name];
    }
    // BIND OUTPUT
    if (!call_user_func_array(array($stmt, 'bind_result'), refValues($parameters))) {
        LOG_MSG('ERROR', "execSQL(): Error binding output params: [" . mysqli_errno($conn) . ": " . mysqli_error($conn) . "].");
        $resp[0]['SQL_ERROR_CODE'] = mysqli_errno($conn);
        mysqli_free_result($result_set);
        // Close result set
        mysqli_stmt_close($stmt);
        // Close statement
        return $resp;
    }
    LOG_MSG('DEBUG', "execSQL():\t Bound output parameters");
    // FETCH DATA
    $i = 0;
    while (mysqli_stmt_fetch($stmt)) {
        $x = array();
        foreach ($row as $key => $val) {
            $x[$key] = $val;
        }
        $results[] = $x;
        $i++;
    }
    $results[0]["NROWS"] = $i;
    $error_message = "";
//.........这里部分代码省略.........
开发者ID:teju,项目名称:Android,代码行数:101,代码来源:db.php

示例9: printf

if (!is_object($res_meta = mysqli_stmt_result_metadata($stmt)) || 'mysqli_result' != get_class($res_meta)) {
    printf("[005] Expecting object/mysqli_result got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
var_dump(mysqli_fetch_assoc($res));
var_dump(mysqli_fetch_assoc($res_meta));
mysqli_free_result($res);
mysqli_free_result($res_meta);
mysqli_stmt_close($stmt);
// !mysqli_stmt_prepare($stmt, "SELECT id, label, id + 1 as _id,  concat(label, '_') _label FROM test as _test ORDER BY id ASC LIMIT 3") ||
if (!($stmt = mysqli_stmt_init($link)) || !mysqli_stmt_prepare($stmt, "SELECT id , label, id + 1 AS _id, label AS _label, null AS _null, CONCAT(label, '_') _label_concat  FROM test _test ORDER BY id ASC LIMIT 3") || !mysqli_stmt_execute($stmt)) {
    printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
    printf("[007] Expecting object/mysqli_result got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (!is_object($res_meta = mysqli_stmt_result_metadata($stmt)) || 'mysqli_result' != get_class($res_meta)) {
    printf("[008] Expecting object/mysqli_result got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (($tmp1 = mysqli_num_fields($res)) !== ($tmp2 = mysqli_num_fields($res_meta))) {
    printf("[009] %s/%s !== %s/%s\n", gettype($tmp1), $tmp1, gettype($tmp2), $tmp2);
}
/*
if (($tmp1 = mysqli_field_count($link)) !== ($tmp2 = $res->field_count()))
	printf("[010] %s/%s !== %s/%s\n", gettype($tmp1), $tmp1, gettype($tmp2), $tmp2);

if (($tmp1 = $res_meta->field_count()) !== $tmp2)
	printf("[011] %s/%s !== %s/%s\n", gettype($tmp1), $tmp1, gettype($tmp2), $tmp2);
*/
if (($tmp1 = mysqli_field_tell($res)) !== ($tmp2 = $res_meta->current_field)) {
    printf("[012] %s/%s !== %s/%s\n", gettype($tmp1), $tmp1, gettype($tmp2), $tmp2);
}
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_mysqli_tests_mysqli_stmt_get_result_metadata.php

示例10: GetMultiRow

 function GetMultiRow()
 {
     global $mysqli;
     $this->_BuildQuery();
     //echo "QRY : " . $this->query . "<BR>";
     $stmt = $mysqli->prepare($this->query);
     $this->_BindWhere($stmt);
     $stmt->execute();
     $data = mysqli_stmt_result_metadata($stmt);
     $fields = array();
     $out = array();
     $fields[0] = $stmt;
     while ($field = mysqli_fetch_field($data)) {
         $fields[] =& $out[$field->name];
     }
     call_user_func_array('mysqli_stmt_bind_result', $fields);
     $results = array();
     while ($stmt->fetch()) {
         $row = array();
         foreach ($out as $key => $value) {
             $row[$key] = $value;
         }
         $results[] = $row;
     }
     return $results;
 }
开发者ID:vinod-co,项目名称:centa,代码行数:26,代码来源:db.php

示例11: db_list_fields

function db_list_fields($result)
{
    if ($result instanceof mysqli_stmt) {
        $meta = mysqli_stmt_result_metadata($result);
        $fields = mysqli_fetch_fields($meta);
    } else {
        $fields = mysqli_fetch_fields($query);
    }
    return array_map(function ($field) {
        return $field->name;
    }, $fields);
}
开发者ID:londomloto,项目名称:immortal,代码行数:12,代码来源:database.php

示例12: printf

        printf("[006] Unexpected field '%s', dumping info\n");
        var_dump($field);
    }
}
if (!empty($field_names)) {
    printf("[007] Field descriptions missing for the following columns\n");
    var_dump($field_names);
}
mysqli_free_result($res);
$stmt = mysqli_stmt_init($link);
/* Depending on your version, the MySQL server migit not support this */
if ($stmt->prepare('EXPLAIN SELECT t1.*, t2.* FROM test AS t1, test AS t2') && $stmt->execute()) {
    if (!mysqli_stmt_store_result($stmt)) {
        printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
    }
    if (!($res_meta = mysqli_stmt_result_metadata($stmt))) {
        printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
    }
    if (($tmp = mysqli_stmt_num_rows($stmt)) !== $num_rows) {
        printf("[010] Expecting int/%d got %s/%s\n", $num_rows, gettype($tmp), $tmp);
    }
    if (($tmp = mysqli_stmt_field_count($stmt)) !== $num_fields) {
        printf("[011] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
    }
    if (($tmp = mysqli_field_count($link)) !== $num_fields) {
        printf("[013] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
    }
    if (($tmp = $res_meta->field_count) !== $num_fields) {
        printf("[014] Expecting int/%d got %s/%s\n", $num_fields, gettype($tmp), $tmp);
    }
    $fields_res_meta = mysqli_fetch_fields($res_meta);
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_mysqli_tests_mysqli_explain_metadata.php

示例13: _fetch

 /**
  * Fetch the result
  * @param resource $result
  * @param int|NULL $arrayIndexEndValue
  * @return array
  */
 function _fetch($result, $arrayIndexEndValue = NULL)
 {
     if ($this->use_prepared_statements != 'Y') {
         return parent::_fetch($result, $arrayIndexEndValue);
     }
     $output = array();
     if (!$this->isConnected() || $this->isError() || !$result) {
         return $output;
     }
     // Prepared stements: bind result variable and fetch data
     $stmt = $result;
     $meta = mysqli_stmt_result_metadata($stmt);
     $fields = mysqli_fetch_fields($meta);
     /**
      * Mysqli has a bug that causes LONGTEXT columns not to get loaded
      * Unless store_result is called before
      * MYSQLI_TYPE for longtext is 252
      */
     $longtext_exists = false;
     foreach ($fields as $field) {
         if (isset($resultArray[$field->name])) {
             $field->name = 'repeat_' . $field->name;
         }
         // Array passed needs to contain references, not values
         $row[$field->name] = "";
         $resultArray[$field->name] =& $row[$field->name];
         if ($field->type == 252) {
             $longtext_exists = true;
         }
     }
     $resultArray = array_merge(array($stmt), $resultArray);
     if ($longtext_exists) {
         mysqli_stmt_store_result($stmt);
     }
     call_user_func_array('mysqli_stmt_bind_result', $resultArray);
     $rows = array();
     while (mysqli_stmt_fetch($stmt)) {
         $resultObject = new stdClass();
         foreach ($resultArray as $key => $value) {
             if ($key === 0) {
                 continue;
                 // Skip stmt object
             }
             if (strpos($key, 'repeat_')) {
                 $key = substr($key, 6);
             }
             $resultObject->{$key} = $value;
         }
         $rows[] = $resultObject;
     }
     mysqli_stmt_close($stmt);
     if ($arrayIndexEndValue) {
         foreach ($rows as $row) {
             $output[$arrayIndexEndValue--] = $row;
         }
     } else {
         $output = $rows;
     }
     if (count($output) == 1) {
         if (isset($arrayIndexEndValue)) {
             return $output;
         } else {
             return $output[0];
         }
     }
     return $output;
 }
开发者ID:kimkucheol,项目名称:xe-core,代码行数:73,代码来源:DBMysqli_innodb.class.php

示例14: printf

}
if (empty($tmp[0]) || empty($tmp[1]) || $tmp[0] != $field0_direct) {
    printf("[012] mysqli_fetch_fields() return value is suspicious\n");
    var_dump($tmp);
}
if (!mysqli_field_seek($res, 1)) {
    printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!is_object($field1_direct = mysqli_fetch_field_direct($res, 1))) {
    printf("[014] Expecting object, got %s/%s, [%d] %s\n", gettype($field1_direct), $field1_direct, mysqli_errno($link), mysqli_error($link));
}
if ($tmp[1] != $field1_direct) {
    printf("[015] mysqli_fetch_field_direct() differs from mysqli_fetch_fields()\n");
    var_dump($field1_direct);
    var_dump($tmp);
}
if (1 !== ($tmp = mysqli_field_tell($res))) {
    printf("[016] Expecting int/1, got %s/%s, [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
}
mysqli_free_result($res);
mysqli_stmt_close($stmt);
if (NULL !== ($tmp = mysqli_stmt_result_metadata($stmt))) {
    printf("[017] Expecting NULL, got %s/%s\n");
}
/* Check that the function alias exists. It's a deprecated function,
	but we have not announce the removal so far, therefore we need to check for it */
if (!is_null($tmp = @mysqli_stmt_result_metadata())) {
    printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_close($link);
print "done!";
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_mysqli_tests_mysqli_stmt_result_metadata.php

示例15: getColumnMeta

 public static function getColumnMeta($index, $sql)
 {
     if ($sql && $index >= 0) {
         $newmeta = array();
         if (get_class($sql) == "mysqli_result") {
             $mt = mysqli_fetch_field_direct($sql, $index);
         } else {
             $fd = mysqli_stmt_result_metadata($sql);
             $mt = mysqli_fetch_field_direct($fd, $index);
         }
         $newmeta["name"] = $mt->name;
         $newmeta["native_type"] = $mt->type;
         $newmeta["len"] = $mt->length;
         return $newmeta;
     }
     return false;
 }
开发者ID:Russell-IO,项目名称:php-syslog-ng,代码行数:17,代码来源:jqGridMysqli.php


注:本文中的mysqli_stmt_result_metadata函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。