mysql - i want to translate SQL to DQL -
i want translate sql statement dql ? have user entity
-------user-------- id username email password ... --------------------
and friend entity wich have 2 attribute friend_one , friend_two reference user
------friend---- id friend_one friend_two statu --------------
so sql statement
update friend set status="1" (friend_one="$user_id" or friend_two="$user_id") , (friend_one="$friend_id" or friend_two="$friend_id")
select 'friend_one','friend_two','status' friend (friend_one="$user_id" or friend_two="$user_id") , (friend_one="$friend_id" or friend_two="$friend_id")
select f.statu, u.username, u.id user u, friend f case when f.friend_one = '$user_id' f.friend_two = u.user_id when f.friend_two= '$user_id' f.friend_one= u.user_id end , f.statu='1'
any please :/
good have tried far? great if include current code in question.
i suggest these queries below: (disclaimer: please note quite raw , haven't been tested)
/* update */ $result = $db->executeupdate('update friend f set f.status = "1" (f.friend_one = ? or f.friend_one = ?) , (f.friend_one = ? or f.friend_two = ?)', array($user_id, $user_id, $friend_id, $friend_id), array(\pdo::param_int, \pdo::param_int, \pdo::param_int, \pdo::param_int) ); /* first select */ $stmt = $db->executequery('select f.friend_one, f.friend_two, f.status friend f (f.friend_one = ? or f.friend_one = ?) , (f.friend_one = ? or f.friend_two = ?)', array($user_id, $user_id, $friend_id, $friend_id), array(\pdo::param_int, \pdo::param_int, \pdo::param_int, \pdo::param_int) ); $result = $stmt->fetchall(); /* second select */ $stmt = $db->executequery('select f.status, u.username, u.id friend f inner join user u on u.user_id = case when f.friend_one = ? f.friend_two when f.friend_two = ? f.friend_one end , f.status = "1"', array($user_id, $user_id), array(\pdo::param_int, \pdo::param_int) ); $result = $stmt->fetchall();
Comments
Post a Comment