Passing a parameter to a bookmark

If we look again at the first bookmark we created (finding all books for author 1), we realize that although it's useful, it's limited to finding just one author—always the same one.

Special query syntax enables the passing of parameters to bookmarks. This syntax uses the fact that SQL comments enclosed within /* and */ are ignored by MySQL. If the /*[VARIABLE]*/ construct exists somewhere in the query, it will be expanded at execution time with the value provided when recalling the bookmark.

Creating a parameterized bookmark

Let us say we want to find all the books for a given author when we don't know the author's id. We first enter the following query:

SELECT author.name, author.id, book.title FROM book, author ...

Get Mastering phpMyAdmin 3.4 for Effective MySQL Management now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.