Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.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_数组?_Php_Sql_Mysql - Fatal编程技术网

Php 布尔字段的mysql_fetch_数组?

Php 布尔字段的mysql_fetch_数组?,php,sql,mysql,Php,Sql,Mysql,我有一个布尔字段,当为true时,它似乎存储为1 在while循环中尝试获取该字段时,我得到错误: mysql_fetch_数组期望参数1是给定的资源布尔值 布尔值应该存储为TRUE而不是1吗 否则,我为什么会得到这个错误 编辑: 我的代码: $sqltotal = mysql_query("SELECT SUM(cost) as total FROM sales where passport = '{$therecord['passport']}' AND {$therecord['paid'

我有一个布尔字段,当为true时,它似乎存储为1

在while循环中尝试获取该字段时,我得到错误:

mysql_fetch_数组期望参数1是给定的资源布尔值

布尔值应该存储为TRUE而不是1吗

否则,我为什么会得到这个错误

编辑:

我的代码:

$sqltotal = mysql_query("SELECT SUM(cost) as total FROM sales where passport = '{$therecord['passport']}' AND {$therecord['paid']} <> 1");
$row = mysql_fetch_array($sqltotal);

您的错误与布尔值的存储方式无关,无论是在数据库中还是在PHP中


mysql\u fetch\u数组的第一个参数必须是您用mysql\u query打开并执行的查询;错误就是这么说的。

这里可能发生了两件事:

您尝试使用类似于$resultset=mysql\u query的代码执行查询。。。;但是来自MySQL的响应是一条错误消息,$resultset包含布尔值FALSE。 您执行了一个不返回结果集的查询,例如INSERT或UPDATE查询,$resultset包含布尔值TRUE,它仅表示查询成功。 调试时,请尝试以下操作:

if ( $resultset === false ) {
    echo mysql_error();
} else {
    // whatever you were doing
}
然而,在生产代码中留下这一点是有危险的,这将对非管理员用户造成威胁。最好是记录错误并向用户显示一般错误消息

if ( $resultset === false ) {
    $message = 'SQL Error in ' . __FILE__ . '@' . (__LINE__ - 2) . ': ' . mysql_error() . "\n";
    error_log($message, 3, ERRLOG); # ERRLOG must be defined
    # or send an e-mail to the developer
    //error_log($message, 1, $developer_email);
    # output an error message to the user. For example:
    ?>
    <p class="error">There was an internal database error. 
      It's been logged, and we'll look into it. Please try again later.
    </p>
    <?php
} else {
    // whatever you were doing
    ...
}

比这更好的是,切换到并使用异常。

好的,我粘贴了我正在使用的代码,然后我应该传递什么到mysql_fetch_array?@Jacob看到Hammerite的答案–您的查询失败了。这可能是一个非常愚蠢的问题,但我会用什么来处理$resultset$行仅在我使用它之后才定义,即在//无论我在做什么部分中…您在我写答案时编辑了您的问题。在代码中扮演my$resultset角色的变量是$sqltotal。您应该查看文档。Quote:mysql_查询在成功时返回资源,在错误时返回FALSE这就是Hammerite和Artefactor所解释的。