Unknown column 'valueToPass' in 'field list' MySQL Error # :1054
I have written a stored procedure in mysql to update. That is working fine, when you execute it in the mysql command line(through Mysql editor).
Stored procedure is:
CREATE DEFINER=`root`@`localhost` PROCEDURE `Deduction_Of_PL`(
IN P_EMPID VARCHAR(1000)
)
BEGIN
DECLARE PresentYearPL VARCHAR(1000);
set PresentYearPL=(select Present_Year_PL from leave_calculate_pl where employee_id=P_EMPID);
IF(PresentYearPL<=0) THEN
UPDATE leave_calculate_pl
SET Carrie_PL=Carrie_PL-1
where employee_id=P_EMPID;
ELSE
UPDATE leave_calculate_pl
SET Present_Year_PL=Present_Year_PL-1
where employee_id= P_EMPID;
END IF;
END $$
And I calling the same Stored procedure in PHP, I am passing the input parameter also.
$LeaveTypeID_G=$this->getLeaveTypeId();
$query_G="CALL Deduction_Of_PL($LeaveTypeID_G)";
Its giving the error as
Unknown 开发者_开发问答column 'parameter_value' in 'field list' MySQL Error # :1054
Please let me know where went wrong and how can I resolve it.
I've just come up against the same issue. I'm trying to pass a logged in user's username to the stored procedure to record it in a log.
The Stored Procedure runs fine when I call it directly (from MySQL Workbench) and was working fine from PHP when I was only passing a date/time. Now that I'm passing this username as a string, however it broke.
For me the fix was to enclose any string parameters in single quote, something like this:
$query = "CALL $procedure_name ( $date_parameter, '$string_parameter')";
Hope that helps anyone else stumbling across this.
well I'm not an expert on sql, and I don't see much php code posted but "Unknown column" to me would be refering to the column names in the sql table in question, or more precisely that it can't find the column you told it to get in that table. first place I'd look at is the select statement your asking it to pull from the column "Present_Year_PL
" I found this to be case senstive so make sure it matches excatly the column name on the table. next place I'd look is in the where statement you told it to match agist the colum "employee_id
" now this is all lower case as oposed to your prevous column name that was all caps, while this is technicaly legal, (As on the actual table you could have one column in all caps and one in all lower,) usally if all caps are used in one column name in a table all the column names are done the same, and vice versa. this would cause a problem your having if say the "employee id" column on the table is "EMPLOYEE_ID" as then "employee_id" actualy does not exist in the table. also be sure your not dooing sometthing like "employeeid" or "employee-id" or even "employee id" as those are verry easy to mistake when eyeballing the field name but will give you the error your getting.
couple of pointers:
- what is the value of the php variabele
$LeaveTypeID_G
?echo $LeaveTypeID_G;
(php) - secondly is MySql invoking a trigger?
show triggers;
(mysql)
精彩评论