News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

What is "$smcFunc['db_quote']"?

Started by Jade Elizabeth, April 02, 2015, 07:03:06 AM

Previous topic - Next topic

Jade Elizabeth

Part of the loadboard function has this line....

'board_link' => empty($topic) ? $smcFunc['db_quote']('{int:current_board}', array('current_board' => $board)) : 't.id_board',

What does $smcFunc['db_quote'] mean/do?
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

margarett

From the code
// Just like the db_query, escape and quote a string, but not executing the query.
function smf_db_quote($db_string, $db_values, $connection = null)
{

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Jade Elizabeth

Are you saying that it is escaping the code following it?

Also is current_board a DB value?
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

margarett

It performs the replacement of the variables in the queries.

Eg, this query
$request = $smcFunc['db_query']('', '
SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
FROM {db_prefix}polls AS p
INNER JOIN {db_prefix}topics AS t ON (t.id_poll = p.id_poll' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ')
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)' . ($topPollInstead ? '
INNER JOIN {db_prefix}poll_choices AS pc ON (pc.id_poll = p.id_poll)' : '') . '
LEFT JOIN {db_prefix}log_polls AS lp ON (lp.id_poll = p.id_poll AND lp.id_member > {int:no_member} AND lp.id_member = {int:current_member})
WHERE p.voting_locked = {int:voting_opened}
AND (p.expire_time = {int:no_expiration} OR {int:current_time} < p.expire_time)
AND ' . ($user_info['is_guest'] ? 'p.guest_vote = {int:guest_vote_allowed}' : 'lp.id_choice IS NULL') . '
AND {query_wanna_see_board}' . (!in_array(0, $boardsAllowed) ? '
AND b.id_board IN ({array_int:boards_allowed_list})' : '') . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND b.id_board != {int:recycle_enable}' : '') . '
ORDER BY ' . ($topPollInstead ? 'pc.votes' : 'p.id_poll') . ' DESC
LIMIT 1',
array(
'current_member' => $user_info['id'],
'boards_allowed_list' => $boardsAllowed,
'is_approved' => 1,
'guest_vote_allowed' => 1,
'no_member' => 0,
'voting_opened' => 0,
'no_expiration' => 0,
'current_time' => time(),
'recycle_enable' => $modSettings['recycle_board'],
)
);

Replaces a bunch of variables replacement. Eg:
{int:recycle_enable} gets replaced by $modSettings['recycle_board']

So current_board is not a DB value. It is a variable that will get the value of $board
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Jade Elizabeth

Where does it get that value from though? I've been combing through this for ages now and I copied the code but changed board to type and topic to work, it's saying "The database value you're trying to insert does not exist: current_type" It has all the right sources and even templates but it just wont work for me. I have searched everywhere for $_REQUEST/$_GET['current_board'] to see if I missed something, I did in querystring, but I covered everything. I dunno what's wrong.

http://pastebin.com/h3Ndti68

I'm trying to make a "workindex" that shows works by types, but for some reason it throws that error. If I go to a work it tells me it's a redirect loop. Not winning for either lol.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Arantor

When you create a query with db_query, it passes everything to db_quote to escape it correctly. You should not normally be touching db_quote for any reason.
Holder of controversial views, all of which my own.


Advertisement: