tags:

views:

17

answers:

1

Hey

I am programming a webpage where the user can upload galleries of his own. When doing so the system creates a subfolder for the images with the same name as the gallery, a reference to the gallery is added as a row in a table and a separate table is also made for the gallery, containing a list of images.

When I try to create a new gallery everything works fine as long as there are no Western European signs. If I for instance name the gallery "beär" I will get an error, "Table 'databasename.beär...' doesn't exist.

The table does however exist with the correct name, I have tried printing out the variable $sub (That represents the gallery name in the query) right before the mysql query that returns an error, it prints correctly.

Also tried mysql_query("SET NAMES 'latin1'", $connection))) and the same with UTF-8 latin1 does nothing, UTF-8 screws everything over even more (The gallery name will actually then be beär).

The text files are encoded in ISO 8859-1, the charset definition is also ISO 8859-1

this is the query:

if(!($result = @ mysql_query("SELECT * FROM {$database}.`{$sub}`
            ORDER BY item_id DESC", $connection)))
        {showerror();}

Any help is greatly appreciated

+5  A: 

Table 'databasename.beär...

You are creating a database table by the name of your gallery. That will not play nicely with special characters in any encoding!

Correction: According to the docs, it is indeed possible to use any alphanumeric character from the current character set! In that case, you need to change your input. Looking at the error message, the ä in Beär is being served as a UTF-8 character. You need to fix that. Is this taking place in an Ajax request? Those are encoded as UTF-8 by default.

In any case, I would feel uneasy using special characters in table names. I wouldn't do it.

Also, creating per-user tables is usually a symptom of a fundamental design mistake. Why not keep all records in one table, identifying the user through a column?

Pekka
+1 Especially regarding the database design.
Pete
It's a per gallery table system, not per user. It's not a community so the users have access to edit the same galleries (If they have the right permissions)Also, even if one should not use special characters if possible, It is at least important to be able to use æ ø and å since they (sadly) are an integral part of Norwegian.The sql query comes from a php script.
Rakoon
@Rakoon creating a table per gallery is poor design. As I said, why not have one big table with a `gallery` field? That would solve all naming problems. Even if you get the special characters working, there will be a lot of gallery names you can't use due to mySQL's naming restrictions.
Pekka
True. I thought about doing it that way when I started making the system, but somehow ended up with the per table design. I'll think about turning it into one big table instead of many small. Thanks a lot for the help.
Rakoon
You are allowed to use any characters you like for schema names, but when you create a table MySQL uses the schema name as the basis for a filename to store the [meta]data in. So if you've got issues with Unicode characters in filenames (and if you're on Windows, you probably do have), I would imagine it could indeed fail. I'd agree that you should generally avoid non-ASCII characters in schema names, and in any case you should never use user input in schema names. The SQL-injection security hole possibilities are endless. And of course as everyone is saying, per-instance tables is a disaster.
bobince