The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Check if user exists Reply To: Check if user exists


I guess I could just automatically update the name, link and image of the user even if their profile data is the same.

If you’re already making a query, then the only extra overhead would be the size of the data you’re sending. A new username or profile image url isn’t much. MySQL is smart enough to ignore updates where the info doesn’t actually change.

The other option would be to store the old (original) data in the session as well as the user’s updated info. That way, you can compare the two and update the DB if necessary.

example using array_diff_assoc:

$original = ["a"=>"A","b"=>"B","c"=>"Sea"];
$updated = ["a"=>"A","b"=>"B","c"=>"C"];

$needs_update = array_diff_assoc( $updated,$original );
// $needs_update contains:  ["c"=>"C"]


the following code echoes out to true

Try id with an id that you know does not exist and see if it returns false. I read the docs on db::select, and for return value it just says “mixed,” so I don’t know what true means in this case. It could be our 1 cast to bool, or it could simply mean that the query didn’t return an error.