mysqlのストアドプロシージャに問題があります。これは私のストアドプロシージャコードです:
DELIMITER $$
CREATE PROCEDURE `projects_grid`(in pagination varchar(100))
BEGIN
DECLARE a,b INT;
declare percent float;
DECLARE cur_1 CURSOR FOR SELECT id FROM tbl_projects;
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET b = 1;
drop temporary table IF EXISTS tbl_temp ;
create Temporary table tbl_temp(id int,name varchar(100) charset utf8,project_name varchar(100) charset utf8,project_type varchar(100) charset utf8,start_date int,end_date int,percent varchar(5));
OPEN cur_1;
REPEAT
FETCH cur_1 INTO a;
set @name='';
set @project_type='';
set @project_name='';
set @b_date='';
set @e_date='';
set @percent='';
set @e_id='';
set @p_id='';
set @completed_rows_count=0;
set @rows_count=0;
select project, (select name from tbl_client where id=tbl_projects.employer_id) as name,(select name from tbl_project_type where id=tbl_projects.project_type_id) as project_name,contract_begin_date,contract_terminate_date into @project_name,@name,@project_type,@b_date,@e_date from tbl_projects where id=a;
SELECT count(PS.status) into @completed_rows_count FROM tbl_projects_status AS PS JOIN tbl_projects_results AS S ON PS.projects_results_id = S.id where project_id=a and PS.status='1';
SELECT count(PS.status) into @rows_count FROM tbl_projects_status AS PS JOIN tbl_projects_results AS S ON PS.projects_results_id = S.id where project_id=a;
set percent=(@completed_rows_count/@rows_count)*100;
insert into tbl_temp values(a,@project_name,@name,@project_type,@b_date,@e_date,concat(percent,'%'));
UNTIL b = 1
END REPEAT;
CLOSE cur_1;
set @pagination=pagination;
set @query=concat('SELECT distinct(id),name,project_name,project_type,start_date,end_date,percent FROM tbl_temp ',@pagination);
PREPARE stmp FROM @query;
EXECUTE stmp;
DEALLOCATE PREPARE stmp;
END
そしてこれは私のphpコードです:
<?php
require_once 'bootstrap.php';
$query="call projects_grid('')";
$result=mysql_fetch_array(mysql_query($query));
foreach($result as $record)
{
echo $record;
}
$query="select count(*) from tbl_projects";
$result=mysql_query($query); // Boolean false given :(
$result=mysql_fetch_row($result);
echo $result[0];
?>
プロシージャの後にクエリを実行すると、デバッグモードで、システムは指定されたブール値をfalse!として表示します。ストアドプロシージャを呼び出した後にクエリを実行するにはどうすればよいですか?