I have just started looking into php pdo and have connected to mysql database and ran a simple SELECT statement. I have a stored function I created before using pdo, do I actually need to use stored functions/procedures while using PDO?
BEGIN
DECLARE new_username VARCHAR(32);
SELECT `username`
INTO new_username
FROM `users`
WHERE `userID` = ID;
RETURN COALESCE(new_username, 'Invalid ID');
END
Is there any point in using the above function, if I'm doing this using PDO? The function will be expanded for other selects etc. I'm also having a problem calling the function using PDO.
include ('connection.php');
$userID = 0;
$stmt = $db->prepare("SELECT username(:user_id)");
$stmt->bindParam(':user_id', $userID, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_OBJ);
echo $result->new_username;
Any advice?