Reputation: 4987
I've got a little problem with exporting MySQL data to html. The problem is that in one field i have values like this: <a href="http://google.com">Google</a>
and when i export the table in html format the generated html table for this fields contains: <a href="http://google.com">Google</a>
which is not a valid html link. Is there way to export the table without mysql to convert the <
and >
chars?
im not using any code. i just use mysql command:mysql -H "select ...."
and specify the output file.
Thanks!
Upvotes: 0
Views: 5042
Reputation: 536339
when i export the table in html format the generated html table for this fields contains:
<a href="http://google.com">Google</a>
That's weird, I don't get that behaviour (in 5.1.34):
$ mysql -H -e "select 'a&b<c>d'";
<TABLE BORDER=1><TR><TH>a&b<c>d</TH></TR><TR><TD>a&b<c>d</TD></TR></TABLE>
And I want the behaviour you quote with the escaping! As you can see from my example, you run the risk of malformed HTML otherwise. eg. a </table>
in a value would break the entire output.
If you want to control the output format to allow raw-HTML content in some or all columns, then (a) you will need to write some code to do this, and (b) you will have to be sure that the content in your database is known-safe HTML, free of malformed strings that might break the table, or malicious JavaScript.
The -H
option to mysql
is insufficient to the task, and seems quite unreliable judging by our different results! You'll want to pick a scripting language with MySQL bindings and output rows manually.
Upvotes: 1
Reputation: 47585
The export purpose is to export data, not to offer a visual explanation of them. You'll have to go with php or any scripting language if you want to have valid link.
By the way, even if you can do it with tricks you should not.
Upvotes: 0