Mysqli绑定param问题

时间:2013-09-12 22:53:01

标签: php mysqli

我正在尝试将数据插入表格中。表结构是

Field                   Type        Null    Key     Default     Extra
id_registro             bigint(20)  NO      PRIMARY             Auto_Increment
id_participante         int(11)     NO          
idf_votante             varchar(25) NO          
periodo                 int(8)      NO          
estado                  char(1)     NO              P   
registrado              timestamp   NO              CURRENT_TIMESTAMP   

我的PHP代码是:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
include "lib/database.config.php"; //database config
        $mysqli = new mysqli($db['host'], $db['user'], $db['password'], $db['database']);
        if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
            exit();
        }
        $sqlAgregarVoto = "INSERT INTO ws_deta_votaciones (`id_participante`, `idf_votante`, `periodo`, `estado`) VALUES(?,?,?,?);";
        $valorPeriodo = 20120101;
        $valorEstado = 'P';
        $a = 1;
        $b= 89;
        $c = 20120101;
        if ($stmt = $mysqli->prepare($sqlAgregarVoto) ){
            //$stmt->bind_param( 'iiis',$_REQUEST['idp'],$_REQUEST['idvf'],$valorPeriodo,$valorEstado)
            $stmt->bind_param( 'iiis',$a,$b,$c,$valorEstado)
            $stmt->execute();               
            } else {
                throw new Exception($stmt->error);
                    }

?>

代码失败,有500个内部错误。

bind_params时代码失败。

1 个答案:

答案 0 :(得分:0)

挑出以下选择陈述

idf_votante             varchar(25) NO          

$sqlAgregarVoto = "INSERT INTO ws_deta_votaciones (`id_participante`, `idf_votante`, `periodo`, `estado`) VALUES(?,?,?,?);";

$b= 89;

$stmt->bind_param( 'iiis',$a,$b,$c,$valorEstado)

看起来你正试图在idf_votante中插入一个整数,idf_votante被定义为varchar(25)。