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) "[email protected]"
    ["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) "[email protected]"
    ["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.

5
  • Sorry, could you explain what result do you expect? Commented Sep 9, 2016 at 21:31
  • @jaro1989 The associative array should have the same datatype defined in the database. (updated question) Commented Sep 9, 2016 at 21:40
  • so.. it's a duplicate to this question: stackoverflow.com/questions/16129432/… Commented Sep 9, 2016 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 Commented Sep 9, 2016 at 21:47
  • and here's for mysqli: stackoverflow.com/questions/5323146/…. 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. Commented Sep 9, 2016 at 22:02

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.