I've got an sql query that contains a number of statements. It:
- sets a user variable
- calls a stored procedure
- calls another stored procedure
- selects some data
I know that the query is correct, because I've tested it in MySQL Workbench, under the same user. The query is this:
set @current_post = 535; /* 535 for testing, this will be a variable */
call under_user_type(@currrent_post, @user_type, @user_id);
call get_category(@current_post, @category);
select p.post_title, p.post_name,
(
swell_wp.post_score(p.ID)
) as score,
(
swell_wp.is_under_user(p.ID, @user_type, @user_id)
) as under_user,
(
swell_wp.is_under_category(p.ID, @category)
) as under_category
from wp_posts as p
where p.post_type = 'post'
and p.id != @current_post
and p.post_status = 'publish'
having (
under_user = true
or under_category = true
)
order by score desc;
that's just stored in a string: $sql
. I then do this with it in PHP:
$query = new MySQLi(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query->multi_query($sql);
do {
$query->next_result();
} while( ! $result = $query->use_result() );
print_r($result);
this prints a result object, but one that is empty. Trying to iterate over it doesn't produce any results either.
What am I doing wrong? Can I even use user variables like this? Or will I need to turn the procedures into stored functions and do three separate queries?