Just as most browsers allow users to bookmark favorite Web sites, phpMyAdmin allows developers to bookmark complex queries, so that they can be easily reused over and over again. As an example, consider the following query, which returns a list of customers along with the services that they have opted for: SELECT clients.cname, services.sname FROM branches, clients, branches_services, services WHERE branches.bid = branches_services.bid AND clients.cid = branches.cid AND branches_services.sid = services.sid This query can easily be bookmarked by popping open the Query window (bottom left of the application) and entering the query above into the query box. Once a result set appears, simply scroll to the bottom of the results page, enter a name for the bookmark, and click the Bookmark this SQL-Query button to save the query to the bookmarks file. When you need to execute the query again, use the SQL tab to obtain a drop-down list of all previously-bookmarked queries. Find the query you bookmarked earlier, select it and Bob's your uncle! You can also use variables in such bookmarked queries. For example, if you want to specify the sid of the service in the query on a per-instance basis, simply alter the query string to look like this: SELECT clients.cname, services.sname FROM branches, clients, branches_services, services WHERE branches.bid = branches_services.bid AND clients.cid = branches.cid AND branches_services.sid = services.sid /* AND services.sid = [VARIABLE] */ Now, run the query. The first time around, phpMyAdmin will ignore the condition between the "/*" and "*/" comment marks and run the query after discounting that section of the query string. No matter; when the result set appears, bookmark this query and then use the SQL tab to run it again. This time, you'll be asked for a value for the sid variable, as seen here. While this is a good feature, be warned that it is still a little buggy: I could not use it with string variables correctly and, while it certainly offers a great way to store complex queries for reuse, it still needs some tweaking.
blog comments powered by Disqus |