I try get pending friend request by this code:

$flag_friend = flag_get_flag('friend');
$friend_p = flag_friend_get_flags($flag_friend, $user->uid);

but it is return error:

PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined.
#0 /home/server/public_html/includes/database/database.inc(2135): PDOStatement->execute(Array)
#1 /home/server/public_html/includes/database/database.inc(664): DatabaseStatementBase->execute(Array, Array)
#2 /home/server/public_html/includes/database/database.inc(2314): DatabaseConnection->query('SELECT fc.*, ff...', Array, Array)
#3 /home/server/public_html/sites/all/modules/flag_friend/flag_friend.module(151): db_query('SELECT fc.*, ff...', Array)
#4 /home/server/public_html/sites/all/themes/server/template.php(433): flag_friend_get_flags(Object(flag_user), '14')
#5 /home/server/public_html/sites/all/themes/server/page.tpl.php(39): muzol_custom_user_tabs(NULL, Array)
#6 /home/server/public_html/includes/theme.inc(1382): include('/home/muzol/pub...')
#7 /home/server/public_html/includes/theme.inc(1072): theme_render_template('sites/all/theme...', Array)
#8 /home/server/public_html/includes/common.inc(5651): theme('page', Array)
#9 /home/server/public_html/includes/common.inc(5518): drupal_render(Array)
#10 /home/server/public_html/includes/common.inc(2550): drupal_render_page('

Is my code correctly?

CommentFileSizeAuthor
#1 flag_friend.patch842 bytesmwesthof

Comments

ShadowMonster’s picture

Issue summary: View changes

change server

mwesthof’s picture

Version: 7.x-1.x-dev » 7.x-1.0-alpha9
StatusFileSize
new842 bytes

The issue with the query seems to be in the PDO placeholders, which contain a dot i.e. ":fc.fid" .

According to PHP SQL Parser source code, PDO placeholders may consist of BINDCHR = [:][a-zA-Z0-9_]+;
See http://lxr.php.net/xref/PHP_5_3/ext/pdo/pdo_sql_parser.re#49

Besides that, it doesn't look like the function is really used. Couldn't find a direct call from the module code.
Also... after getting the query to run, the next error is on foreach ($result as $new_flag) {, where $result should be $resultS.

So a quick fix could be:

function flag_friend_get_flags($flag, $content_id, $reset = NULL) {
  static $flagged_content;
  $uid = $content_id;
  $content_type = $flag->content_type;

  if (!isset($flagged_content[$uid][$content_type][$content_id]) || $reset) {
    $flags = flag_get_flags($flag->content_type);
    $flagged_content[$uid][$content_type][$content_id] = array();

    // get flags with messages
    $results = db_query("SELECT fc.*, ffm.message FROM {flag_content} fc LEFT JOIN {flag_friend_message} ffm ON ffm.fcid = fc.fcid WHERE fc.fid = :fc_fid AND fc.content_type = :fc_content_type AND fc.content_id = :fc_content_id", 
      array(
        ':fc_fid' => $flag->fid,
        ':fc_content_type' => $content_type, 
        ':fc_content_id' => $content_id
      )
    )->fetchAll();
    foreach ($results as $new_flag) {
      $fcid = flag_friend_get_fcid($flag, $content_id, $new_flag->uid);
      $flagged_content[$uid][$content_type][$content_id][$fcid] = $new_flag;
      $flagged_content[$uid][$content_type][$content_id][$fcid]->user = user_load($new_flag->uid);
    }
  }

  return $flagged_content[$uid][$content_type][$content_id];
}

Added the patch for those interested...

mwesthof’s picture

Issue summary: View changes

other changing