perl and mysql, creating dynamic tables
I was wondering if there开发者_JAVA百科 are some example coding to create dynamic tables with x columns? I am worried about column names having funny characters.
regards, Gordon
I guess you want escape these characters in table names. Use quote_identifier DBI method
Why would you want to dynamically create tables? You ought to be designing a suitable database schema to suit the data you need to store.
My impression based on your question is that you're doing it wrong.
Creating tables is easily done with a standard CREATE TABLE command, though, for instance:
$dbh->do('CREATE TABLE testtable (foo VARCHAR(100), bar INT(4), baz DATETIME);');
You could generate that SQL easily enough, and there's no reason you should end up with any "funny characters".
I'm still not convinced that this is the right solution to whatever you're trying to do though, perhaps you could expand the question with more information on why you're trying to do this, as I get the feeling it's not thought through fully and will end up with a database structure that's an unmaintainable mess.
If you're trying to store dynamic data that doesn't fit well into a traditional relational database schema, you could also consider document-centric databases like MongoDB (which stores JSON-based "documents" of data, giving you a lot of flexibility; there's a MongoDB module on CPAN to interface with it easily).
精彩评论