I am trying to quickly determine if a user_ID is the owner of a \'goal\'. I believe my SQL query is good, but I\'m trying to find a nice way of checking the result!
SELECT EXISTS always returns a row! The following code uses the fastest MySql query(according to this answer: https://stackoverflow.com/a/10688065/3710053) and gives in PHP the correct result:
$link = mysqli_connect($DB_SERV, $DB_USER, $DB_PASS, $DB_NAME);
$query = "SELECT EXISTS (SELECT * FROM goals
WHERE goal_ID='$obj_id'
AND user_ID='$user_id'
LIMIT 1)
as `row_exists`";
if(mysqli_fetch_assoc(mysqli_query($link,$query))['row_exists'] ===0) {
// Nothing found!
}