【问题标题】:Error - Number of elements in type definition string doesn't match number of bind variables错误 - 类型定义字符串中的元素数与绑定变量数不匹配
【发布时间】:2014-08-05 12:11:22
【问题描述】:
$call = "CALL spuser( ?,  ?,?,)" ;
$stmt = $connection2->prepare($call);
if ( !$stmt ) {
   die('prepare failed');
}
if ( !$stmt->bind_param('ssssssss',$_POST['name'],$_POST['lname'],$_POST['address']) ) {
   // $stmt->error has more info
   die('bind failed');
}
if ( !$stmt->execute() ) {
   // $stmt->error has more info
   die('execute failed');
}

$stmt->close();

存储过程是:

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `spuser`(

IN id bigint, IN name varchar(25), IN lname varchar(25), IN address varchar(25), IN phoneno varchar(10), IN city varchar(10) )
BEGIN

Insert INTO user( name, lname, address, phoneno, city ) values (name, lname, address, phoneno, city) ;

END

根据我的项目要求,我必须在存储过程中将 5 个字段作为 IN 参数,但在调用过程时,我将来只需要使用 3 个其他字段。

【问题讨论】:

  • 你能格式化你的问题吗?
  • bind_params() 和 spuser() 之间存在参数不匹配。
  • 1. spuser() - 声明和调用时参数数量不匹配。
  • 2. bind_params - 如果提供给绑定的参数,则此处也与数字不匹配。

标签: php mysql mysqli


【解决方案1】:

我看到两个错误。 1) $call = "CALL spuser( ?, ?,?,)"; 只需要三个参数,但您传递的是 4:$stmt->bind_param('ssssssss',$_POST['name'],$_POST['lname'],$_POST['address'])

2) 您的存储过程需要 5 个参数,因此您需要传递 5 个参数。如果您还不知道这些值,请传递 null 或创建另一个存储过程。 有关存储过程的可选参数,请参阅此问题:Writing optional parameters within stored procedures in MySQL?

【讨论】:

    猜你喜欢
    • 2016-05-24
    • 2015-09-20
    • 2013-06-18
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    相关资源
    最近更新 更多