0

I'm using Laravel on a Windows workstation, and on a Linux, I'm running a test with the following line only:

echo gettype(Patient::find(11)->case_id);

I've added this column like this:

$table->integer('case_id');

the db is on the linux, and I connect remotely from the windows.

the result: on the windows machine: "integer", on the linux machine: "string"

(This caused a terrible bug where I used === expecting it to be integer...)

Any ideas?

NiRR
  • 4,782
  • 5
  • 32
  • 60

1 Answers1

1

The difference comes from the way the different MySQL drivers present the extracted data from the database.
More specifically using only strings in the Linux case.

The fastest way to fix that is to use comparison that look like:
($case_id == 5) // true instead of ($case_id === 5) // false assuming $case_id="5";

Maybe the Linux driver also can be tuned to return not only strings.
If you provide driver specific info maybe somebody can help you more with fine tuning the driver.

In case you are using PDO, then those will help:

$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

The second line has nothing to do with the strings, but is recommended.

Antoan Milkov
  • 2,152
  • 17
  • 30
  • Thanks for the reply! can you make sure that I understand what you are saying and look if this is the relevant thread? http://stackoverflow.com/questions/20079320/php-pdo-mysql-how-do-i-return-integer-and-numeric-columns-from-mysql-as-int – NiRR Oct 29 '14 at 09:15