Any query you have executed can be stored as a bookmark on the page where the results are displayed. You will find a button labeled ‘Bookmark this query’ just at the end of the page. As soon as you have stored a bookmark, it is related to the database you run the query on. You can now access a bookmark dropdown on each page, the query box appears on for that database.

You can also have, inside the query, a placeholder for a variable. This is done by inserting into the query a SQL comment between /* and */. Inside the comment, the special string [VARIABLE] is used. Be aware that the whole query minus the SQL comment must be valid by itself, otherwise you won’t be able to store it as a bookmark.

When you execute the bookmark, everything typed into the value input box on the query box page will replace the string /*[VARIABLE]*/ in your stored query.

Also remember, that everything else inside the /*[VARIABLE]*/ string for your query will remain the way it is, but will be stripped of the /**/ chars. So you can use:

/*, [VARIABLE] AS myname */

which will be expanded to

, VARIABLE as myname

in your query, where VARIABLE is the string you entered in the input box. If an empty string is provided, no replacements are made.

A more complex example. Say you have stored this query:

SELECT Name, Address FROM addresses WHERE 1 /* AND Name LIKE '%[VARIABLE]%' */

Say, you now enter “phpMyAdmin” as the variable for the stored query, the full query will be:

SELECT Name, Address FROM addresses WHERE 1 AND Name LIKE '%phpMyAdmin%'

You can use multiple occurrences of /*[VARIABLE]*/ in a single query (that is, multiple occurrences of the same variable).

NOTE THE ABSENCE OF SPACES inside the /**/ construct. Any spaces inserted there will be later also inserted as spaces in your query and may lead to unexpected results especially when using the variable expansion inside of a “LIKE ‘’” expression.

Your initial query which is going to be stored as a bookmark has to yield at least one result row so you can store the bookmark. You may have that to work around using well positioned /**/ comments.

Posted in: PhpMyAdmin

Related FAQ's

Marius Ion ANGEL HOT SOFT LLC (800) 316-7677