سؤال

When I do a var_dump immediately after a find in CakePHP, all the field values are listed as having a data type of strings, despite the fields in the database being integers, floats, booleans, or whatever else that's not a string. Should it be this way, or have I done something wrong in CakePHP, the configuration, or the database driver? I'm working on an application written in CakePHP version 1.3 with the mysqli driver (the mysql driver behaves the same).

هل كانت مفيدة؟

المحلول

To be expected

CakePHP only returns what the underlying driver returns, as such it is Db-dependent, but if you're observing all values are strings then yes, it should be that way.

For example, using the mysql driver results are always returned as strings:

<?php

mysql_connect("localhost", "user", "pass");

$resource = mysql_query("select * from cakephp.posts");

$myrow = mysql_fetch_row($resource);
var_dump($myrow);

Results in:

array(5) {
  [0] => string(1) "1" # <- autoincrement int primary key value
  [1] => string(9) "The title"
  [2] => string(22) "This is the post body."
  [3] => string(19) "2013-08-01 07:34:57"
  [4] => string(19) "2013-08-01 07:34:57"
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top