我的存储过程:
DROP PROCEDURE IF EXISTS alphaindia.insertcoursedetails;
CREATE DEFINER=`root`@`localhost` PROCEDURE `insertcoursedetails`( IN `StartDate` DATE,IN `ChurchName` VARCHAR(50), IN `CourseTypeId` BIGINT, IN `Participants` BIGINT, IN `MxId` VARCHAR( 50 ) , IN `DateCreated` DATE, IN `LocationName` VARCHAR( 100 ) , IN `LocationLatitude` VARCHAR( 50 ) , IN `LocationLongitude` VARCHAR( 50 ) , IN `LocationAddress` VARCHAR( 300 ) )
NO SQL
INSERT INTO coursedetails( StartDate, ChurchName, CourseTypeId, Participants, MxId, DateCreated, LocationName, LocationLatitude, LocationLongitude, LocationAddress )
ALUES (
StartDate, ChurchName, CourseTypeId, Participants, MxId, DateCreated, LocationName, LocationLatitude, LocationLongitude, LocationAddress
)
PHP代码:
$date = date('d/m/Y');
echo $date;
mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error());
mysql_select_db("alphaindia");
$result = mysql_query("Call insertcoursedetails('2/3/2014','$_SESSION['ChurchLead']','$_SESSION['courseid']','$_SESSION['NumbPart']','vini.katyal','2/3/2014','$_SESSION['shortname']','$_SESSION['lat'],'$_SESSION['long'],'$_SESSION['address']'");
if($result)
{
echo("<br>Data Input OK");
}
else
{
echo("<br>Data Input Failed");
}
我无法通过php中的存储过程插入数据。请帮忙
答案 0 :(得分:0)
在双引号字符串中,PHP可以评估变量名称,如
echo "My name is $name";
但是使用数组你必须使用花括号来成功评估你的语句。 以下陈述有效
echo "My name is {$_SESSION['name']}";
你会得到
PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
如果你这样做
echo "My name is $_SESSION['name']";
这就是您的查询中发生的事情。
答案 1 :(得分:0)
你的程序应该是这样的:
DROP PROCEDURE IF EXISTS alphaindia.insertcoursedetails;
DELIMITER $$
CREATE DEFINER=`root`@`localhost`
PROCEDURE `insertcoursedetails`(IN `StartDate` DATE,IN `ChurchName` VARCHAR(50), IN `CourseTypeId` BIGINT, IN `Participants` BIGINT, IN `MxId` VARCHAR( 50 ) , IN `DateCreated` DATE, IN `LocationName` VARCHAR( 100 ) , IN `LocationLatitude` VARCHAR( 50 ) , IN `LocationLongitude` VARCHAR( 50 ) , IN `LocationAddress` VARCHAR( 300 ) )
BEGIN
INSERT INTO coursedetails( StartDate, ChurchName, CourseTypeId, Participants, MxId, DateCreated, LocationName, LocationLatitude, LocationLongitude, LocationAddress )
VALUES (
StartDate, ChurchName, CourseTypeId, Participants, MxId, DateCreated, LocationName, LocationLatitude, LocationLongitude, LocationAddress
)
END$$
您需要在过程中添加BEGIN
和END
。
在此处阅读Procedure。