-- Step 1: Prepare an INSERT statement to insert a user into the users table
PREPARE insert_stmt FROM 'INSERT INTO users (name, email) VALUES (?, ?)';
-- Step 2: Set values for placeholders
SET @name = 'John Doe', @email = 'john.doe@example.com';
-- Step 3: Execute the prepared INSERT statement with the provided values
EXECUTE insert_stmt USING @name, @email;
-- Step 4: Deallocate the prepared INSERT statement
DEALLOCATE PREPARE insert_stmt;
-- Step 5: Prepare a SELECT statement to retrieve user by ID
PREPARE select_stmt FROM 'SELECT id, name, email FROM users WHERE id = ?';
-- Step 6: Set the value for the ID of the user to retrieve
SET @id = 1;
-- Step 7: Execute the SELECT statement with the ID
EXECUTE select_stmt USING @id;
-- Step 8: Deallocate the prepared SELECT statement
DEALLOCATE PREPARE select_stmt;
No hay comentarios:
Publicar un comentario