Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
503 views
in Q2A Core by
I have been trying to use single sign-on with Wikimedia & Question2Answer without much luck.

Looking at my server error messages it appears that there is a problem connecting to the database to get the user details. I have the following line in my qa-external-users.php file:

$result = mysql_fetch_assoc( mysql_query( "SELECT user_id, user_name, user_email FROM user WHERE user_id = " . $userid, $qa_db_connection ) );

however, in my error log I get the following php error:

mysql_query() expects parameter 2 to be resource, object given in /qa-external/qa-external-users.php

 

Have I missed something or is this a bug?
Q2A version: 1.7.3

1 Answer

+1 vote
by

The problem is that you are using the mysql functions instead of mysqli. The old mysql extension has been deprecated for years, and in fact removed in the newest version of PHP.

So the $qa_db_connection variable that you have is a MySQLi object. The simplest solution is to use the existing Q2A functions which handle escaping data (for security) as well:

$result = qa_db_read_one_assoc(qa_db_query_sub(
    'SELECT user_id, user_name, user_email FROM user WHERE user_id = #',
    $userid
));

 

Edit: I just noticed that the comments in the example external-users file are (incorrectly) suggesting to use the mysql_* functions. I will fix those shortly.

...