Can anyone point me to a regular expression in PHP which could be used to
check that a proposed (My)SQL database/table/column name is valid, i.e.
shouldn't result in an SQL error when created?
The user of my (hopefully to be opensourced) program has the ability to
create database/table/column names on the fly.
I'm aware of obvious characters such as ., [space], things like >, etc.,
which won't work, but haven't been able to source a definitive list,
including having googled the MySQL site.
Obviously certain characters need to be filtered out, as noted above, but
I want to be as unrestrictive as possible; hence just [a-z]* isn't good
enough because things like _ are acceptable.
Ideally, I'd prefer a regexp that applies to _all_ vendors' databases, not
just MySQL as I'm about to migrate the program to being
database-independent, probably using PEAR DB, but even a MySQL-specific
regexp would do the job.
In the longer term, I plan some sort of entity conversion script so that
theoretically any character could be used, using some sort of escaping
mechanism probably.
Can anyone supply or suggest routes to such a regexp?
Martin Lucas-Smith
www.geog.cam.ac.uk/~mvl22 www.lucas-smith.co.uk
Senior Computing Technician (Web Technician)
Department of Geography, University of Cambridge (01223 3)33390
& Webmaster, SPRI
Scott Polar Research Institute, University of Cambridge