Mysql result data types
| From: | Reinis Rozitis | Date: | Thu, 12 Oct 2017 11:55:35 +0000 |
| Subject: | Mysql result data types | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-100868@lists.php.net to get a copy of this message | ||
Hello,
is there a reason (technical or historical) why the data coming from MySQL is always strings?
I've found only one case where the data type is "honored" - PDO+mysqlnd+emulation off
[1]
We made a fairly simple patch to 'mysqlnd' which enables (configurable via ini) data to be
returned (trying to match) as defined in database/table.
In general something like:
switch( field->type ){
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_SHORT:
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_INT24:
convert_to_long(data);
break;
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_DOUBLE:
case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_NEWDECIMAL:
convert_to_double(data);
break;
}
Does it make sense to create a PR and/or RFC for something like this?
[1] https://phpdelusions.net/pdo#returntypes
wbr
Reinis Rozitis