Insert with accent and latin1 characters
I have next table in my database of MySQL:
CREATE TABLE cities ( idcity int(10) unsigned NOT NULL auto_increment, city varchar(50) NOT NULL, PRIMARY KEY (idcity), ) ENGINE=latin1 DEFAULT CHARSET=latin1;
I will have around 8000 cities (aprox) and my query is right:
INSERT INTO cities (city) VALUES ('Barcelona'),('Álava'), ('Cáceres'), ... until 8000 cities of Spain.
What I don't want to do it is to use in PHPutf8_decode because I have 8000 registers.
In PHP I have the insert inside a string and after I execute the query. table creates right as latin1
How can MySQL recognize the accents of that cities?
There's absolutely no need to encode data manually (and please don't ever use utf8_decode() without looking up in the PHP manual what it actually does).
Most likely, you're failing to set the connection encoding when you connect to MySQL:
In PDO, use the constructor:
new PDO('mysql:host=localhost;dbname=foo;charset=utf8', ....);
In MySQLi, call set_charset():
Now, don't type utf8 blindly. You need to find out what encoding your app is using.
Simply use utf8_general_ci collation in SQL table for your city varchar.