gpt4 book ai didi

php - 出现错误 - SQLSTATE [21000] : Cardinality violation: 1241 Operand should contain 1 column(s)

转载 作者:可可西里 更新时间:2023-11-01 07:02:46 24 4
gpt4 key购买 nike

我收到这个错误SQLSTATE[21000]:违反基数:1241 操作数应包含 1 列谁能帮我理解为什么?

这是我的代码:

<?php


session_start();
$turk_number ='';
$serial='';
$version='';
if(isset($_POST['turk_number']))
{
$_SESSION['turk_number'] = $_POST['turk_number'];
$turk_number= $_POST['turk_number'];
}

$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "resolver";

try
{
$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query1 = "SELECT ((SELECT * FROM participants ORDER BY serial DESC LIMIT 0, 1) % 10) + 1 as version";
//$results = $dbh->query($query1);
$results = $dbh->prepare($query1);
$results->execute();
$serial = $results->fetchColumn(0);
if($test= $results->fetchColumn(1))
{
$version = $test; //last version on record + 1
}
else //if no user ever played any games
{
$version = 1;
}
$query2 = "INSERT INTO participants (version) VALUES (:version, :turk_number)";
$stmt = $dbh ->prepare($query2);
$stmt ->execute(array(':version' => $version,
':turk_number' => $turk_number));

}
catch(PDOException $e)
{
echo $e->getMessage();
}

$_SESSION['serial']= $serial;
$_SESSION['version']=$version;


?>
serial <?php print $serial; ?><br />
version <?php print $version; ?><br />
turk <?php print $turk_number; ?>

最佳答案

您正在选择内部查询中的所有列,然后尝试执行 %10,这会给您错误,因为您不能 %10 到多个列。将其切换为选择一列。

(SELECT * FROM participants ORDER BY serial DESC LIMIT 0, 1) % 10

选择多个列,然后尝试将其修改 10

关于php - 出现错误 - SQLSTATE [21000] : Cardinality violation: 1241 Operand should contain 1 column(s),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14864052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com