Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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 PDO MYSQL-获取,其中不返回任何结果_Php_Mysql_Pdo - Fatal编程技术网

PHP PDO MYSQL-获取,其中不返回任何结果

PHP PDO MYSQL-获取,其中不返回任何结果,php,mysql,pdo,Php,Mysql,Pdo,当一列等于该列中的值时,我试图获取结果。我的代码运行时,where子句已从查询中删除,但不会抛出错误,但foreach不会运行 $themes = Singlequery ('SELECT * FROM items WHERE type = :theme ORDER BY id = :id DESC LIMIT 5', array('theme' => ['theme'], 'id' => ['id']), $conn); <?p

当一列等于该列中的值时,我试图获取结果。我的代码运行时,where子句已从查询中删除,但不会抛出错误,但foreach不会运行

$themes = Singlequery ('SELECT * FROM items WHERE type = :theme ORDER BY id = :id DESC LIMIT 5', 
                      array('theme' => ['theme'], 'id' => ['id']), $conn);

<?php foreach ($themes as $theme) : ?>
      <li><a href="#"><?= $theme['name']; ?></a></li>
<?php endforeach; ?>
您可以继续使用PHP:

$themes = Singlequery ('SELECT * 
                        FROM items 
                        WHERE type = :theme 
                        ORDER BY id = :id DESC 
                        LIMIT 5', 
                        array('theme' => $myTheme, 
                              'id'    => $myId), 
                        $conn);

foreach ($themes as $theme) {
  echo '<li><a href="#">'.$theme['name'].'</a></li>'.PHP_EOL;
}
您仍然需要为$myTheme和$myId提供一个值。

您可以继续使用PHP:

$themes = Singlequery ('SELECT * 
                        FROM items 
                        WHERE type = :theme 
                        ORDER BY id = :id DESC 
                        LIMIT 5', 
                        array('theme' => $myTheme, 
                              'id'    => $myId), 
                        $conn);

foreach ($themes as $theme) {
  echo '<li><a href="#">'.$theme['name'].'</a></li>'.PHP_EOL;
}

您仍然需要为$myteme和$myId提供一个值。

您正在绑定一个数组

数组'theme'=>['theme'],'id'=>['id']


['theme']相当于array0=>'theme'

您正在绑定一个数组

数组'theme'=>['theme'],'id'=>['id']


['theme']相当于数组0=>'theme'

您的参数数组是错误的,它应该是:

array(':theme' => $theme, ':id' => $id)
注意:在那里。同样,您的值实际上是数组。当PDO开始绑定时,它将需要字符串,并找到一个数组,因此,如果参数一开始就起作用,那么很可能您的查询将产生以下等价项:

SELECT ... WHERE type = 'Array' ORDER BY id = 'id'

您的参数数组错误,应为:

array(':theme' => $theme, ':id' => $id)
注意:在那里。同样,您的值实际上是数组。当PDO开始绑定时,它将需要字符串,并找到一个数组,因此,如果参数一开始就起作用,那么很可能您的查询将产生以下等价项:

SELECT ... WHERE type = 'Array' ORDER BY id = 'id'
尝试使用echo$stmt->errorCode调试Singlequery函数并打印\r$stmt->errorInfo。并在此处发布结果。我的代码运行时从查询中删除where子句-您的查询失败。但是没有错误被抛出-你在检查它们吗setAttributePDO::ATTR_ERRMODE,PDO::ERRMODE_exception使用echo$stmt->errorCode和print\r$stmt->errorInfo调试Singlequery函数。并在此处发布结果。我的代码运行时从查询中删除where子句-您的查询失败。但是没有错误被抛出-你在检查它们吗setAttributePDO::ATTR_ERRMODE,PDO::ERRMODE_异常