3

I have the following code on a PHP script:

$DB = new MeekroDB($host, $user, $pass, $dbIntra, $port, $encoding);    
$DB->throw_exception_on_error = true;
$DB->error_handler = false;
$DB->throw_exception_on_nonsql_error = true;

$result = $DB->query("SELECT usr_id, usr_username, usr_blocked, usr_language, usr_nickname, entc_id FROM usuario LIMIT 1");

var_dump($result);

Resulting in the following:

array(1) {
  [0]=>
  array(6) {
    ["usr_id"]=>
    string(1) "1"
    ["usr_username"]=>
    string(12) "igor@ppp.com"
    ["usr_blocked"]=>
    string(1) "0"
    ["usr_language"]=>
    string(2) "ES"
    ["usr_nickname"]=>
    string(5) "Ivan1"
    ["entc_id"]=>
    string(1) "1"
  }
}

Is there any way to have MeekroDB respect the datatypes assigned in the database model?

UPDATE

Also tried with PDO with the same result, it seems it is not MeekroDB but PHP:

$dbh = new PDO('mysql:host=...;dbname=...', $user, $pass); 
$query="SELECT usr_id, usr_username, usr_blocked, usr_language, usr_nickname, entc_id FROM usuario LIMIT 1";
$data = $dbh->query($query);
$result = $data->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);

UPDATE

I would expect something like this:

array(1) {
  [0]=>
  array(6) {
    ["usr_id"]=>
    int(1) 1                          // Notice int
    ["usr_username"]=>
    string(12) "igor@ppp.com"
    ["usr_blocked"]=>
    int(1) 0                          // Notice int
    ["usr_language"]=>
    string(2) "ES"
    ["usr_nickname"]=>
    string(5) "Ivan1"
    ["entc_id"]=>
    int(1) 1                          // Notice int
  }
}

The associative array should have the same datatype defined in the database.

supercoco
  • 512
  • 2
  • 7
  • 25
  • Sorry, could you explain what result do you expect? – jaro1989 Sep 09 '16 at 21:31
  • @jaro1989 The associative array should have the same datatype defined in the database. (updated question) – supercoco Sep 09 '16 at 21:40
  • so.. it's a duplicate to this question: http://stackoverflow.com/questions/16129432/why-not-pdo-mysql-return-integer – jaro1989 Sep 09 '16 at 21:42
  • wasn't really a duplicate since originally asked for MeekroDB (uses mysqli behind the scenes)... later tried with PDO... but thanks for the feedback – supercoco Sep 09 '16 at 21:47
  • and here's for mysqli: http://stackoverflow.com/questions/5323146/mysql-integer-field-is-returned-as-string-in-php. MeekroDB is just a little upgrade over mysqli and nothing more. I'd better not use such (bad written btw) approaches. But it's up to you. – jaro1989 Sep 09 '16 at 22:02

1 Answers1

1

With Meekro you cannot get typed results, as it is not using prepared statements - the only way to get the data type right off the fetch.

With PDO, it is possible only if PDO is built upon mysqlnd and emulation mode is turned off. Having there prerequisites, you can have your results already in corresponding types

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345