Are you sure that the 500 error is thrown when calling set_userdata?
First thing you can do is enable error_reporting. One way to do this is by setting your environment to 'development' in your main index.php file, provided also that you have enabled error reporting in your php.ini. After doing this you will probably see a more detailed error message that will help you identify the problem.
On the other hand looking at your code I see the line 'pic' => $row -> pic,<br>
and that <br>
definitely produces an error when initializing your array, maybe this is the case