Readers: 7
1
2
3
4
5
6
7
8
9
# PHP
$dbh = dbh(); # PDO Objekt
$c = pack("CC", 195, 164); # ä
$sql = "insert into test (txt)values('$c')";
$sth = $dbh->query($sql);
# Perl
my $c = pack("CC", 195, 164);
$dbh->do("insert into test (txt)values('$c')");
1
2
3
4
5
6
7
8
9
<?php
# PHP
$dbh = new PDO('mysql:host=localhost;dbname=testdb', 'test', 'test');
$c = pack("CC", 195, 164); # ä
$sql = "insert into test (text) values('$c')";
$sth = $dbh->query($sql);
1
2
3
4
5
6
7
8
MariaDB [testdb]> explain test;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| text | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0,001 sec)
1
2
3
4
5
6
7
MariaDB [testdb]> SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'test';
+--------------+------------+--------------------+
| TABLE_SCHEMA | TABLE_NAME | TABLE_COLLATION |
+--------------+------------+--------------------+
| testdb | test | utf8mb4_general_ci |
+--------------+------------+--------------------+
1 row in set (0,001 sec)
1
2
3
4
5
6
7
MariaDB [testdb]> select * from test;
+------+------+
| id | text |
+------+------+
| NULL | ä |
+------+------+
1 row in set (0,000 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@servana:~# php --version
PHP 7.4.33 (cli) (built: Feb 22 2023 20:07:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
root@servana:~#
root@servana:~# mariadb --version
mariadb Ver 15.1 Distrib 10.5.19-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
root@servana:~#
root@servana:~# dpkg -l | grep php | grep ii | grep mysql
ii php-mariadb-mysql-kbs 1.2.12-1 all Knowledge base about MariaDB and MySQL server variables
ii php-mysql 2:7.4+76 all MySQL module for PHP [default]
ii php7.4-mysql 7.4.33-1+deb11u3 amd64 MySQL module for PHP
root@servana:~#
2023-06-07T16:19:17 rostiIch glaub dier ja, aber zum Nachtesten, ich hätte da gern ein Beispiel und wüsste was welches PHP und welche PDO-Anbindung und wie die Datenbank kodiert und welche DB-Version das ist.Genau das ist ja das Problem: PHP kodiert.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $c = "ᎤࢣࣘဃလͶ᠓ᠴᡠᣲ";
my $dbh = DBI->connect(
"DBI:mysql:testdb;host=localhost",
"test", "test",
{'RaiseError' => 1}
);
$dbh->do("insert into test (text) values ('$c')");
1
2
3
4
5
6
7
8
9
10
<?php
# PHP
$dbh = new PDO('mysql:host=localhost;dbname=testdb', 'test', 'test');
# $c = pack("CC", 195, 164); # ä
$c = "ᎤࢣࣘဃလͶ᠓ᠴᡠᣲ";
$sql = "insert into test (text) values('$c')";
$sth = $dbh->query($sql);
QuoteIch bin wohl zu dusslich, dein Problem zu erfassen.
2023-06-07T18:07:31 rostiNein. Das Problem ist wohl daß ich hier eine uralte PHP Version habe.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
$VAR1 = [ { 'c' => '�', 'd' => 'PHP', 'length(c)' => '2' }, { 'c' => '�', 'd' => 'PHP', 'length(c)' => '2' }, { 'c' => "\x{20ac}", 'd' => 'Perl', 'length(c)' => '7' }, { 'c' => "\x{e4}", 'd' => 'Perl', 'length(c)' => '4' } ];
1
2
3
4
5
6
CREATE TABLE `chr` (
`c` text CHARACTER SET utf8 COLLATE utf8_bin,
`d` varchar(123) NOT NULL DEFAULT 'Perl',
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8
2023-06-08T08:25:55 rostiDu hast recht bianca, meine Fehlerbeschreibung war falsch (*).
1
2
3
4
CREATE TABLE `chr` (
`c` text CHARACTER SET utf8 COLLATE utf8_bin,
`d` varchar(123) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8
2023-06-08T08:05:13 GwenDragonUm diesem Kodierungswahn von PHP-/Perl-Modulen aus dem Weg zu gehen, hilft nur das roh als blob in der DB abzuspeichern wie du schon erwähntest.
1
2
3
4
5
6
7
8
9
10
11
12
13
CREATE TABLE `forum` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`fid` varchar(32) NOT NULL DEFAULT '',
`pid` int(11) NOT NULL DEFAULT '0',
`comment` text,
`nickname` varchar(32) NOT NULL DEFAULT '',
`tid` int(11) NOT NULL DEFAULT '0',
`subject` varchar(72) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `fid` (`fid`),
KEY `tid` (`tid`)
) ENGINE=InnoDB AUTO_INCREMENT=371 DEFAULT CHARSET=latin1
1
2
3
4
5
6
CREATE TABLE `chr` (
`c` text CHARACTER SET utf8 COLLATE utf8_bin,
`d` varchar(123) NOT NULL DEFAULT 'Perl',
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8
1
2
3
4
5
6
7
8
9
$VAR1 = [
{
'c' => '€',
'd' => 'Perl',
'hex(c)' => 'C3A2E2809AC2AC',
'id' => '1',
'length(c)' => '7'
}
];
1
2
3
4
5
6
7
8
mysql> show variables like "character_set%";
+--------------------------+---------------+
| Variable_name | Value |
+--------------------------+---------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_results | utf8 |
+--------------------------+---------------+
1 2 3 4 5 6 7 8
$dbh->do(q( create table cc( c varchar(123) charset latin1 )default charset latin1 )); $dbh->do("insert into cc(c)values('€')"); print $dbh->selectrow_array("select hex(c) from cc"); # E282AC $dbh->do('drop table cc');
1
2
3
4
5
6
7
8
mysql> show variables like 'character_set%';
+--------------------------+---------------+
| Variable_name | Value |
+--------------------------+---------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_results | utf8 |
+--------------------------+---------------+
QuoteDu musst utf8mb4 nehmen.
2023-06-14T06:27:53 rostigrößere Datenmenge?QuoteDu musst utf8mb4 nehmen.
PS: charset utf8mb4 reserviert 4 Bytes für JEDES Zeichen! Aus varchar(100) wird varchar(400)! Was das für indizierte Felder bedeutet weißt Du?
https://de.wikipedia.org/wiki/Gro%C3%9Fes_%C3%9F... Seit dem 29. Juni 2017 ist das große Eszett (ẞ) Bestandteil der amtlichen deutschen Rechtschreibung. ...
QuoteEin großes Eszett ẞ ist sinnvoll.
Programmierer sind ungebildet was Typografie anbelangt, wenn sie da lachen.
ich verstehe nicht, warum du so sarkastisch agierst.
https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-sets.html(Hervorhebung von mir)utf8mb4: A UTF-8 encoding of the Unicode character set using one to four bytes per character.
https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html#data-types-storage-reqs-stringsTo calculate the number of bytes used to store a particular CHAR, VARCHAR, or TEXT column value, you must take into account the character set used for that column and whether the value contains multibyte characters. In particular, when using a UTF-8 Unicode character set, you must keep in mind that not all characters use the same number of bytes. utf8mb3 and utf8mb4 character sets can require up to three and four bytes per character, respectively. For a breakdown of the storage used for different categories of utf8mb3 or utf8mb4 characters, see Section 10.9, “Unicode Support”.