Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Michael T. Richter

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Get HTML/XML output of your MySQL queries.

The mysql command line utility can be used to build databases, manipulate them, etc. It can also be used as an ad-hoc query tool with HTML-snippet output. Consider this code:

mysql -e "SELECT * FROM mytable WHERE somecondition='somevalue'"


The resulting output will be a mess of +, - and | characters used to frame boxes around the values. Now consider instead:

mysql -H -e "SELECT * FROM mytable WHERE somecondition='somevalue'"


The output of this is <TABLE/><TR/><TD/> code that can be cut-and-pasted into your HTML editor of choice. Complex queries not easily put into a single -e string can be done thus:

mysql -H < myqueries.sql


Note that no HTML is generated for any query that does not have a result set (like INSERT or UPDATE).

Change the -H to a -X to get XML output (without a DTD/XSL description, unfortunately).
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS