MySQLi在函数失败时执行不返回false

I have a function to insert into a table, then insert into another with LAST_INSERT_ID and finally return the LAST_INSERT_ID. It works fine except that there is a foreign key that can make the function fail error 1452. This happens when I test with a bad foreign key in MySQLWorkbench with this query:

SELECT create_match(1,2);

However in PHP, if the function fails it still returns true.

    $query = "SELECT create_match(?,?)";
    if (!$stmt = $this->mysqli->prepare($query))
        error_log("CreateMatch() Failed to prepare statement: " . $this->mysqli->error . __FILE__ . " Line: " . __LINE__,0);
    else {
        $stmt->bind_param('ii', $gameID, $userID);
        $success = $stmt->execute();
        $stmt->bind_result($res);
        $stmt->fetch();
    }

$success is true even if the function failed. Why might this be and how can I detect if the function failed? I am weary about testing it in the function because I am returning an unsigned int and any number could be valid.