Fabrizio Bartolomucci
Fabrizio Bartolomucci

Reputation: 4958

Insert data by php on Maria db in forma swe7

I formatted a field of a table in my MariaDB in swe7 to host strings from the Swedish alphabet. Yet when I try to enter them in my php script I receive error:

error INSERT INTO palette (number, address, latitude, longitude, timestamp) VALUES ('7470618', "Östersund Tallbacksvägen", 63.18874861617303, 14.6445424430311, 1440249233) ON DUPLICATE KEY UPDATE number='7470618', address="Östersund Tallbacksvägen", latitude=63.18874861617303, longitude=14.6445424430311, timestamp=1440249233 error:Incorrect string value: '\xC3\x96ster...' for column 'address' at row 1

When instead I execute the query directly on the DB, the query is correctly execute and the row inserted. So I think the issue is in the php script, perhaps in the format of its strings, but I do not know how to adjust it.

Thanks for your support

Upvotes: 0

Views: 80

Answers (2)

Rick James
Rick James

Reputation: 142306

C396 is the utf8 hex encoding for Ö

Do you want to use swe7 because you have data encoded that way?

  • SET NAMES swe7 (or equivalent) when connecting to mysql from your client.
  • For the CHARACTER SET in your tables, you could use either utf8 or swe7. With utf8, you allow other languages to be handled.
  • If the output is on web pages, be sure to have the appropriate <meta...charset> specified. (I don't know how to spell 'swe7' in that context.)

Or do you have some other reason for wanting swe7?

Addeda

Plan A: Use swe7 throughout -- SET NAMES, CHARACTER SET, html meta.

Plan B: SET NAMES swe7 and a suitable value for html meta charset, but CHARACTER SET utf8 in the tables.

Either way, the client will see only swe7 encodings.

Upvotes: 0

Fabrizio Bartolomucci
Fabrizio Bartolomucci

Reputation: 4958

Ok, the solution was using utf8 and performing the two commands:

$mysqli->query("SET NAMES utf8");
mysqli_set_charset('utf8');

At that point the encoding in the sql table is irrelevant between utf8 and swe7.

Doing that with swe7 does not work, though.

Upvotes: 0

Related Questions