Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP-MYSQL中,使用“fetch_assoc()”在准备好的语句中使用多个“WHERE”子句打印“SELECT*”设置的结果的正确方法是什么?_Php_Mysqli_Prepared Statement_Fetch_Where Clause - Fatal编程技术网

在PHP-MYSQL中,使用“fetch_assoc()”在准备好的语句中使用多个“WHERE”子句打印“SELECT*”设置的结果的正确方法是什么?

在PHP-MYSQL中,使用“fetch_assoc()”在准备好的语句中使用多个“WHERE”子句打印“SELECT*”设置的结果的正确方法是什么?,php,mysqli,prepared-statement,fetch,where-clause,Php,Mysqli,Prepared Statement,Fetch,Where Clause,我的问题如下: $query = 'SELECT * FROM `table_name` WHERE `uid` = ? AND `email` = ?'; $stmt_select = $conn->prepare($query); $stmt_select->bind_param('is', $user_id, $user_email); $user_id = $_SESSION['uid']; $user_email = $_SESSION['user_email']; $re

我的问题如下:

$query = 'SELECT * FROM `table_name` WHERE `uid` = ? AND `email` = ?';
$stmt_select = $conn->prepare($query);
$stmt_select->bind_param('is', $user_id, $user_email);
$user_id = $_SESSION['uid'];
$user_email = $_SESSION['user_email'];
$result = $stmt_select->execute();
我想使用
fetch\u assoc
打印结果集,这是因为我不想
bind\u result()
到所有23列的名称,我想使用
$row['column\u name']
打印它,实现它的正确方法是什么

如果您想查看我的代码,我在这里问了另一个问题:


但是它没有得到正确的回答,因此,除了更正我的代码,你能告诉我实现它的最佳方法吗?

我在mysqli中使用
SELECT*
时遇到了同样的问题。问题在于
bind_结果
部分。通常需要添加许多变量。这意味着如果您有大约20列,那么需要在
bind\u result
语句中包含20个变量

我已经定制了解决方案来解决您的问题

  $query = 'SELECT * FROM `table_name` WHERE `uid` = ? AND `email` = ?';
    $stmt_select = $conn->prepare($query);
    $stmt_select->bind_param('is', $user_id, $user_email);
    $user_id = $_SESSION['uid'];
    $user_email = $_SESSION['user_email'];
    $result = $stmt_select->execute();
   $stmt_select->store_result();//after this line we can output the number of rows if you need to check that as well
   $number_of_rows = $stmt_select->num_rows;
   $meta = $stmt_select ->result_metadata();
   $parameters = array();
  $results = array();
  while ($field = $meta->fetch_field()) {
         $parameters[] = &$row[$field->name];
  }
  call_user_func_array(array($stmt_select , 'bind_result'), $parameters);
       while ($stmt_select ->fetch()) {
             foreach ($row as $key => $val) {
                  $x[$key] = $val; //here we get the key => value (Column => Value)
                      }
                      $results[] = $x; //lets grab everything here
                  }
print_r($results);

我在mysqli中使用
SELECT*
时遇到了同样的问题。问题在于
bind_结果
部分。通常需要添加许多变量。这意味着如果您有大约20列,那么需要在
bind\u result
语句中包含20个变量

我已经定制了解决方案来解决您的问题

  $query = 'SELECT * FROM `table_name` WHERE `uid` = ? AND `email` = ?';
    $stmt_select = $conn->prepare($query);
    $stmt_select->bind_param('is', $user_id, $user_email);
    $user_id = $_SESSION['uid'];
    $user_email = $_SESSION['user_email'];
    $result = $stmt_select->execute();
   $stmt_select->store_result();//after this line we can output the number of rows if you need to check that as well
   $number_of_rows = $stmt_select->num_rows;
   $meta = $stmt_select ->result_metadata();
   $parameters = array();
  $results = array();
  while ($field = $meta->fetch_field()) {
         $parameters[] = &$row[$field->name];
  }
  call_user_func_array(array($stmt_select , 'bind_result'), $parameters);
       while ($stmt_select ->fetch()) {
             foreach ($row as $key => $val) {
                  $x[$key] = $val; //here we get the key => value (Column => Value)
                      }
                      $results[] = $x; //lets grab everything here
                  }
print_r($results);

我希望我的答案对@user7984467有帮助。我希望我的答案对@user7984467有帮助。这就像预期的一样!!祝你在未来的项目中好运!这就像预期的一样!!祝你在未来的项目中好运!