为什么MySQL和PHP的这种组合不起作用?

时间:2015-07-16 11:47:13

标签: php mysql

有人能告诉我以下MySQL程序和PHP脚本是否有效?

我在这里设置了mysql程序,我觉得它很有意义,但PHP脚本会打印错误。我猜测有0行受影响了吗?

MySQL的:

DELIMITER $$
CREATE procedure spPlayer (IN pName NVARCHAR(50), IN pMobileNumber NVARCHAR(50), IN pTime datetime, OUT pID INT)
begin

select count(*) into @cnt FROM tblnewusers;
IF @cnt < 12 THEN
    insert into tblplayers (Name, MobileNumber, Time)
    values
    (pName, pMobileNumber, pTime);
    SELECT pID = @@IDENTITY;
END IF;
END$$
DELIMITER ;

PHP:

<?php
$dt = new datetime();
$name = "Test";
$mobile = "1234567";
$time = $dt->format('Y-m-d H:i:s');

$dbhost = 'dbHost here';
$dbuser = 'dbUser here';
$dbpass = 'dbPass here';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn)
{
    die('Could not connect: '. mysql_error());
}   

mysql_select_db("SafeDropbox", $conn);

$result = mysql_query("CALL spPlayer();");

if($result) {
    echo "Success";
}
else {
    echo "Error";   
}

?>

EDIT 这是MySql表设置它有帮助!

enter image description here

1 个答案:

答案 0 :(得分:0)

这是一个假设的答案,这可能会更加详细和精炼:

当您echo mysql_error();时,它会为您生成以下错误:

  

错误不正确PROCEDURE的参数数量safedropbox.spPlayer;   预计4,得到0

创建过程时,可以使用4个参数进行设置:

CREATE procedure spPlayer (IN pName NVARCHAR(50), IN pMobileNumber NVARCHAR(50), IN pTime datetime, OUT pID INT)

因此,当你调用它时,你可能还需要为spPlayer提供4个参数:

$result = mysql_query("CALL spPlayer();");