Can anyone tell me if the following MySQL procedure along with a PHP script work?
I've set up mysql procedure here and I think it makes sense but the PHP script will print error. By that I'm guessing that there were 0 rows effected?
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 Here's the MySql table set up it it helps!
This is an assumption answer, and this could definetly be more detailed and refined:
When you echo mysql_error();
it produces the following error for you:
ErrorIncorrect number of arguments for PROCEDURE safedropbox.spPlayer; expected 4, got 0
When you created your procedure you set it with 4 arguments:
CREATE procedure spPlayer (IN pName NVARCHAR(50), IN pMobileNumber NVARCHAR(50), IN pTime datetime, OUT pID INT)
Hence, when you call it you might need to provide spPlayer
with with 4 arguments as well:
$result = mysql_query("CALL spPlayer();");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.