0
votes

I'm doing some social activity page on phalcon but there is a strange problem on get feeds. Im doing raw query on phalcon , but when i write code manually its working , but when set/get from jquery to php its not.

Manually code (its working):

$sql  = "SELECT S.*,S.user_one as user_id,S.id,U.username,U.profile_photo 
FROM users U, social S
WHERE 
CASE

WHEN `user_one` = $user_id
THEN `user_two` = `user_id`
WHEN `user_two` = $user_id
THEN `user_one`= `user_id`
END


AND
(`user_one` = $user_id OR `user_two` =$user_id) Group by S.id ORDER BY S.id DESC LIMIT 20 OFFSET 0";

 // Base model
 $social = new Social();



   // Execute the query
  return new Resultset(null, $social, $social->getReadConnection()->query($sql));

But same query same code but only get from jquery (its crypting)

 public static function runAjaxQuery($sql)
     {


        // Base model
        $social = new Social();



        // Execute the query
        return new Resultset(null, $social, $social->getReadConnection()->query($sql));

        }

On second i got that error : SELECT S.*,S.user_one as user_id,S.id,U.username,U.profile_photo FROM users U, social S WHERE CASE WHEN user_one = 6 THEN user_two = user_id WHEN user_two = 6 THEN user_one= user_id END AND (user_one = 6 OR user_two =6) Group by S.id ORDER BY S.id DESC LIMIT 20 OFFSET 20SQLSTATE[42000]: Syntax error or access violation: 1064 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 '"SELECT S.*,S.user_one as user_id,S.id,U.username,U.profile_photo FROM users U,' at line 1

Thanks for all

1
Copy your query and paste it in phpmyadmin or mysql directly (substituting the variables) and see if it runs there. This seems to be a syntax error than a Phalcon error. - Nikolaos Dimopoulos
Where is user_two defined? - Nikolaos Dimopoulos
@NikolaosDimopoulos its working on phpmyadmin. , user_two not selected column , only on where column - Muhammet Arslan
can you please post your javascript part - Reda

1 Answers

0
votes

Take a look at the error message from MySQL:

check the manual that corresponds to your MySQL server version for the right syntax to use near '"SELECT S.*,S.user_one as user_id,S.id,U.username,U.profile_photo FROM users U,' at line 1

Note that you have a double quote before SELECT; this means that you send MySQL something like this:

"SELECT S.*,S.user_one as user_id,S.id,U.username,U.profile_photo FROM users U,..."

You need to strip the double quotes around the query.