[SOLVED] sql_build_array isn't working properly >:(

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Toxyy
Registered User
Posts: 938
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek
Contact:

[SOLVED] sql_build_array isn't working properly >:(

Post by Toxyy »

EDIT so it turns out it's working fine. Explanation:
$sql_аry vs $sql_ary. What's the difference between these two strings? The first one has a russian lowercase а for some odd reason, and only that letter. I don't know why or how that happened.

This can be closed :oops:
------------------------------------
(yes I added $phpbb_dispatcher to the global vars at the top of the function to get events to work, thanks Marc in the discord for that...)

So I made an event (no pr yet) in functions_admin.php, in the sync function, forums case:

Code: Select all

$sql_аry = array(
	'SELECT'	=> 'p.post_id, p.poster_id, p.post_subject, p.post_time, p.post_username, u.username, u.user_colour',
	'FROM'		=> array(
		POSTS_TABLE	=> 'p',
		USERS_TABLE => 'u',
	),
	'WHERE'		=> $db->sql_in_set('p.post_id', $post_ids) . '
		AND p.poster_id = u.user_id',
);

/**
* Event to modify the SQL array to get the post and user data from all forums' last posts
*
* @event core.sync_forum_last_post_info_sql
* @var	array	sql_аry		SQL array with some post and user data from the last posts list
* @since 3.2.6-RC1
*/
$vars = array('sql_аry');
extract($phpbb_dispatcher->trigger_event('core.sync_forum_last_post_info_sql', compact($vars)));

$result = $db->sql_query($db->sql_build_query('SELECT', $sql_аry));
Works great! I've seen doing $sql = $db->sql_build_query('SELECT', $sql_аry) before the actual sql_query, but whatever.

Now, I did the same exact thing (no pr yet) in functions_posting.php right after the query, just like before:

Code: Select all

$sql_ary = array(
	'SELECT'	=> 'p.' . $type . '_id, p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour',
	'FROM'		=> array(
		POSTS_TABLE	=> 'p',
		USERS_TABLE => 'u',
	),
	'WHERE'		=> $db->sql_in_set('p.post_id', $last_post_ids) . '
		AND p.poster_id = u.user_id',
);

/**
* Event to modify the SQL array to get the post and user data from all last posts
*
* @event core.update_post_info_modify_posts_sql
* @var	string	type				The table being updated (forum or topic)
* @var	array	sql_ary				SQL array to get some of the last posts' data
* @since 3.2.6-RC1
*/
$vars = array(
	'type',
	'sql_ary',
);
extract($phpbb_dispatcher->trigger_event('core.update_post_info_modify_posts_sql', compact($vars)));
$sql = $db->sql_build_query('SELECT', $sql_аry);
$result = $db->sql_query($sql);
(I know I did it the way I said before, both ways give the same error)
and I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM ()' at line 1 [1064]

aand

[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/driver.php on line 716: Invalid argument supplied for foreach()

So, I decided to do var_dump/print_r on the sql_build_query and I got:
SELECT FROM()

a completely blank query....

even more fun, if I try to do var_dump/print_r on the $sql_ary var itself, it's null. Hell I even copied code from another function that uses sql_build_query for a select query and it also messes up.

Wtf?
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

Some of my extensions:
[3.3][BETA] Post Form Templates || [3.3][BETA] Anonymous Posts || [3.2][3.3][BETA] ACP Merge Child Forums || [3.2][BETA] Sticky Ad || [3.2][DEV] User Delete Topics || [3.3][DEV] Moderate While Searching || [3.3][RC] Short Number Twig Extension
Post Reply

Return to “Extension Writers Discussion”