简体   繁体   English

准备的语句,而循环错误的PHP

[英]prepared statement while loop error php

public function suggest(){
$SQL = "SELECT CategoryName FROM tb_category WHERE CategoryName LIKE CONCAT('%', ?, '%')";
$stmt = $this->_db->mysqli->prepare($SQL);
$stmt->bind_param("s", $this->querystring);
$stmt->execute();
$meta = $stmt->result_metadata();  
while($field = $meta->fetch_field())
    {     
     $parameters[] = &$row[$field->name];
     //print_r($parameters); 
    }

In my while -loop its giving the on thing again and again just checking the single row in db not the whole table I guess there isn't any problem with like operator here 在我的while -loop中,它一次又一次地给on事情,只是检查db中的单行而不是整个表,我想这里的like运算符没有任何问题

Just to be sure i understood well: 为了确保我理解得很好:

while($field = $meta->fetch_field())
{     
 $parameters[] = &$row[$field->name];
 //print_r($parameters); 
}

Suppose you query returns 10 rows, does this while execute 10 times? 假设您的查询返回了10行,这是否执行10次?

Try $row[$field->name]; 尝试$row[$field->name]; instead of &$row[$field->name]; 而不是&$row[$field->name]; (without & ) (不带&

finally fetch_field() returns the definitions of the columns you retreived with your query. 最后, fetch_field()返回您在查询中检索到的列的定义。 As you select only CategoryName you are printing only CategoryName column definitions 当您仅选择CategoryName您仅打印CategoryName列定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM