php - execute query after call mysql stored procedure -
i have problem store procedures in mysql. store procedure code:
delimiter $$ create procedure `projects_grid`(in pagination varchar(100)) begin declare a,b int; declare percent float; declare cur_1 cursor select id tbl_projects; declare go on handler 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 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 tbl_client id=tbl_projects.employer_id) name,(select name tbl_project_type id=tbl_projects.project_type_id) project_name,contract_begin_date,contract_terminate_date @project_name,@name,@project_type,@b_date,@e_date tbl_projects id=a; select count(ps.status) @completed_rows_count tbl_projects_status ps bring together tbl_projects_results s on ps.projects_results_id = s.id project_id=a , ps.status='1'; select count(ps.status) @rows_count tbl_projects_status ps bring together tbl_projects_results s on ps.projects_results_id = s.id project_id=a; set percent=(@completed_rows_count/@rows_count)*100; insert 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 tbl_temp ',@pagination); prepare stmp @query; execute stmp; deallocate prepare stmp; end
and php code:
<?php require_once 'bootstrap.php'; $query="call projects_grid('')"; $result=mysql_fetch_array(mysql_query($query)); foreach($result $record) { echo $record; } $query="select count(*) tbl_projects"; $result=mysql_query($query); // boolean false given :( $result=mysql_fetch_row($result); echo $result[0]; ?>
when execute query after procedure, @ debug mode, scheme shows me given boolean false!. how can execute query after phone call stored procedure?
finally found answer: utilize mysqli instead mysql.
$mysqli = new mysqli('your_hostname','your_username' ,'your_password','your_db_name'); $result=$mysqli->query($query); $result->data_seek(0);
after execute query must utilize commands:
mysqli_free_result(); mysqli_next_result($mysqli);
good luck!
php mysql stored-procedures
No comments:
Post a Comment