Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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 mysqli bind_result仅适用于INT类型的列_Php_Mysql_Mysqli_Prepared Statement - Fatal编程技术网

Php mysqli bind_result仅适用于INT类型的列

Php mysqli bind_result仅适用于INT类型的列,php,mysql,mysqli,prepared-statement,Php,Mysql,Mysqli,Prepared Statement,我将mySQL表定义为: CREATE TABLE IF NOT EXISTS `coupons` ( `coupon_id` int(11) NOT NULL auto_increment, `coupon_code` varchar(50) NOT NULL, `coupon_expiration_date` date NOT NULL, `coupon_discount` decimal(10,2) NOT NULL, `coupon_created

我将mySQL表定义为:

CREATE TABLE IF NOT EXISTS `coupons` (
    `coupon_id` int(11) NOT NULL auto_increment,
    `coupon_code` varchar(50) NOT NULL,
    `coupon_expiration_date` date NOT NULL,
    `coupon_discount` decimal(10,2) NOT NULL,
    `coupon_created_date` date NOT NULL,
    PRIMARY KEY  (`coupon_id`)
)
此表中的一个条目如下:

INSERT INTO `coupons` (`coupon_id`, `coupon_code`, `coupon_expiration_date`, `coupon_discount`, `coupon_created_date`) VALUES (1, 'test', '2012-11-30', '11.00', '2012-10-22');
尝试使用以下PHP代码查询此表时:

$strSelectCoupons = "SELECT coupon_id FROM coupons";
if($stmtSelectCoupons = $mysqlConn->prepare($strSelectCoupons))
{
    $stmtSelectCoupons->execute();
    $stmtSelectCoupons->bind_result($iCouponId);

    while($stmtSelectCoupons->fetch())
    {
        echo $iCouponId;
    }
}
else
{
    echo "Prepared statement error: " . $mysqlConn->error;
}
$strSelectCoupons = "SELECT coupon_id, coupon_code FROM coupons";
if($stmtSelectCoupons = $mysqlConn->prepare($strSelectCoupons))
{
    $stmtSelectCoupons->execute();
    $stmtSelectCoupons->bind_result($iCouponId, $strCouponCode);

    while($stmtSelectCoupons->fetch())
    {
        echo $iCouponId . "<br />";
        echo $strCouponCode . "<br />";
    }
}
else
{
    echo "Prepared statement error: " . $mysqlConn->error;
}
正如预期的那样,我们看到一个“1”打印到屏幕上

但是,如果我们尝试执行以下PHP代码:

$strSelectCoupons = "SELECT coupon_id FROM coupons";
if($stmtSelectCoupons = $mysqlConn->prepare($strSelectCoupons))
{
    $stmtSelectCoupons->execute();
    $stmtSelectCoupons->bind_result($iCouponId);

    while($stmtSelectCoupons->fetch())
    {
        echo $iCouponId;
    }
}
else
{
    echo "Prepared statement error: " . $mysqlConn->error;
}
$strSelectCoupons = "SELECT coupon_id, coupon_code FROM coupons";
if($stmtSelectCoupons = $mysqlConn->prepare($strSelectCoupons))
{
    $stmtSelectCoupons->execute();
    $stmtSelectCoupons->bind_result($iCouponId, $strCouponCode);

    while($stmtSelectCoupons->fetch())
    {
        echo $iCouponId . "<br />";
        echo $strCouponCode . "<br />";
    }
}
else
{
    echo "Prepared statement error: " . $mysqlConn->error;
}
$strselectcoups=“从优惠券中选择优惠券id、优惠券代码”;
如果($stmtselectcoups=$mysqlConn->prepare($strselectcoups))
{
$stmtselecttups->execute();
$stmtselectculops->bind_result($iCouponId,$strCouponCode);
而($stmtselectcoups->fetch())
{
echo$iCouponId。“
”; echo$strCouponCode.“
”; } } 其他的 { echo“准备好的语句错误:”.$mysqlConn->错误; }
不显示结果,不打印错误,不记录错误,页面的其余部分不呈现

事实上,唯一一次,这实际上是预期的工作时,只返回优惠券的id。例如,如果我们改变select语句只返回优惠券代码,这将再次导致页面爆炸

关于是什么导致这一失败,有什么想法吗

Apache版本:2.2.2

PHP版本:5.3.14

mySQL版本:5.0.95-community

编辑:

根据进一步的调查,bind_result仅适用于INT类型的列,并且在尝试绑定其他类型的任何列时失败。

对指向的点的注释会导致大数据列崩溃


据报道,mysqlnd和MySQL的Connector/C没有出现这个问题,或者如果可能,您可以在调用
mysqli\u stmt\u bind\u result()

非常古老的主题之前调用,但我发现了一个“解决方案”,一个奇怪的解决方案,如果

if(!$stmtSelectCoupons->bind_result($iCouponId, $strCouponCode)) { // TODO error }

您确定
优惠券\u code
实际上是表中某列的名称吗?也许某个地方有输入错误?只是想知道-当您执行工作查询时,优惠券id自动增量是否实际增加了值?sgroves:
优惠券\u code
是表中列的实际名称。除了
优惠券id
之外的所有列都会出现此问题。PhilNerd:auto\u increment是
优惠券id
列的一个属性,因此当我将记录插入表中时,
优惠券id
将增加1,这与选择行无关。