On 5 Feb 2005 11:36:20 -0800,
co**********@yahoo.com (cocoalearner) wrote:
I am serving a website using apache. All the php and mysql code I have
written works, except for one thing. When I try to create a database
named M#2 using the following call, no database is created.
$db = 'M#2';
$query = "create database '$db'";
$result = @mysql_query($query);
Removing the error suppression operator, checking $result and printing
mysql_error() may give some sort of clue.
Shouldn't you be using backticks `` to quote identifiers, i.e. the database
name, rather than single quotes '' which are for strings?
I am able to create a database just fine using this technique when it
is named other things (such as M$B, or Global1). I am able to create
the database using CocoaMySQL. The MySQL documentation I read says the
only characters you cannot use are , . / and \, but they don't mention
"#". Also, it mentions that if you can have any database name that can
be used as a directory name. I am able to create a directory name in
unix called "M#2".
Any ideas about how to get this to work? Thank you in advance for any
help.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 4.0.21
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database 'M#2';
ERROR 1064: You have an error in your SQL syntax. Check the manual that
corresponds to your MySQL server version for the right syntax to use near
''M#2'' at line 1
mysql> create database `M#2`;
Query OK, 1 row affected (0.06 sec)
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool