MyBB Community Forums
Update query with returning - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Update query with returning (/thread-207027.html)



Update query with returning - Augustino7 - 2016-12-31

I want to do like that


$sql="UPDATE mybb_users SET ".$campo."='".$partes[3]."' WHERE uid='".$partes[1]."' RETURNING id AS afectados;";
 $respuesta=$db->query($sql);
$afectados=$db->fetch_field($respuesta, 'afectados');


but with this:

$update_array = array(
$campo => $info[4]
);
$r=$db->update_query('users', $update_array, "uid = {$nombre_usuario['uid']}","RETURNING id AS afectados;");

$afectados=$db->fetch_field($r, 'afectados');

Is possible?


RE: Update query with returning - Matt - 2016-12-31

You can't return a value from an update query, in MyBB or otherwise, just the number of affected rows.


RE: Update query with returning - Augustino7 - 2016-12-31

In postgresql is possible but not with  $db->update_query
Well, thanks, I got it, with just affected rows, because just I need know if the update was successfully done


            $db->update_query('users', $update_array, "uid = {$nombre_usuario['uid']}");
$afectados=$db->affected_rows();


thanks and best regards


RE: Update query with returning - Matt - 2016-12-31

Oh, I assumed it was MySQL, my bad! Glad I pointed you in the right direction by accident Toungue