0

I have the following schema:

CREATE DATABASE `matla_test` COLLATE `utf8mb4_unicode_ci`;
use matla_test;
CREATE TABLE `testTypes`(`number` int,   `text`   varchar(10));
INSERT INTO `matla_test`.`testTypes` VALUES (4, "four");

making query into database:

$db = new PDO($dns, $username, $password, [
    PDO::ATTR_PERSISTENT => false,
    PDO::ATTR_ERRMODE=> PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_STRINGIFY_FETCHES=> false,
    PDO::ATTR_EMULATE_PREPARES=> false,
    PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC
]);
var_dump($db->query('SELECT * from testTypes')->fetchAll());

When I connect directly to database, I get correct data types:

array(1) {
  [0] =>
  array(2) {
    'number' =>
    int(4)
    'text' =>
    string(4) "four"
  }
}

but when I connect through maxscale I get all as string:

array(1) {
  [0] =>
  array(2) {
    'number' =>
    string(1) "4"
    'text' =>
    string(4) "four"
  }
}

MariaDB MaxScale 2.5.7 nebo 6.1.1

php ini:

PHP Version => 7.3.18-1+ubuntu19.10.1+deb.sury.org+1
...
pdo_mysql

PDO Driver for MySQL => enabled
Client API version => mysqlnd 5.0.12-dev - 20150407 - $Id: 7cc7cc96e675f6d72e5cf0f267f48e167c2abb23 $

Directive => Local Value => Master Value
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
...

if I try something similar in Python it returns correct types

import mysql.connector
import json

cnx = mysql.connector.connect(user='matla', database='matla_test', password='8YhdsLr3LdYnqSGu0Frk', host='mysql.pc.deso.cz', port= '4006')
cursor = cnx.cursor()

query = ("SELECT * FROM testTypes")

cursor.execute(query)
for record in cursor:
 print(json.dumps(record))

cursor.close()
cnx.close()
[4, "four"]
[5, "5"]

Any idea how to get numeric as int with PDO and maxscale and PHP 7.2?

UPDATE

4

0 回答 0