Thread [PHP] PDO und utf8 (49 answers)
Opened by rosti at 2023-06-06 13:34

GwenDragon
 2023-06-07 14:17
#194967 #194967
User since
2005-01-17
14748 Artikel
Admin1
[Homepage]
user image
Bei dir wird keine PDO-Exception geworfen? Was für eine Fehlermeldung bekommst du, wenn nur das eine Byte drin ist? Gar keine?




Ich kenne dein Encoding der Tabelle nicht.
Aber Perk kanns bestimmt mit utf8mb4
https://metacpan.org/pod/DBD::mysql#mysql_enable_u...




Also bei mir mit MariaDB geht das ohne blobberei. ;-)

Code: (dl )
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);


Tabelle test:
Code: (dl )
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)


Collation:
Code: (dl )
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)


Inhalt der Tabelle test:
Code: (dl )
1
2
3
4
5
6
7
MariaDB [testdb]> select * from test;
+------+------+
| id | text |
+------+------+
| NULL | ä |
+------+------+
1 row in set (0,000 sec)


Version PHP, MariaDB und PDO:
Code: (dl )
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:~#


Ausschnitt der Ausgabe von php -iv | grep pdo_mysql -A4
Code: (dl )
1
2
3
4
5
6

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => mysqlnd 7.4.33

Last edited: 2023-06-07 14:51:45 +0200 (CEST)

View full thread [PHP] PDO und utf8