0

I'm having problem with PHP and Oracle database.

When I insert a number in table from PHP, the number in the table become strange number. For example when I running query from PHP to insert number '1' into table, it will not store number '1' but it store to another number like '4294967296'. When I insert number '10' it become '4294967306', and so on. The data type is NUMBER (10,0).

oracle table

There is no problem when I change to another database like MySQL with the same table structure. When I insert '1' it will store '1' too. Also there is no problem after I upload the program to Ubuntu Server. Oracle store the same number from PHP.

I develop the PHP program with Laravel Framework in my Windows Laptop using Laragon.

I don't have any idea what is the problem. Is it PHP, my Laptop, Laravel, Laragon or the Oracle?

Thank you for your help and answer.

fahmi rizal
  • 33
  • 1
  • 7
  • 1
    Can you show us your php code? How you are inserting it? – atokpas May 12 '17 at 03:35
  • I'm using eloquent Laravel. My code: `$user = new User; $user->id = 1; $user->name='lolol'; $user->username= 'lolol'; $user->active_directory=0; $user->save();` – fahmi rizal May 12 '17 at 03:59
  • I just find out that, when I insert using raw code, there is no problem too. `DB::insert('insert into users (id, username, name, email, active_directory, domain) values (?, ?, ?, ?, ?, ?)', [10,'dayle', 'Dayle', 'dayle', '0', 'esdm']);`. But still, when I use `$user->save()` it doesn't work. – fahmi rizal May 12 '17 at 04:09
  • Is this happening for the `id` column? – linuxartisan May 12 '17 at 04:31
  • No. Not only ID, but all column with data type NUMBER. – fahmi rizal May 12 '17 at 04:46

1 Answers1

0

I'm using mutator to cast the attribute into string. Because, it will work if I insert string ('0') into table instead of integer (0). Below is the mutator in User model:

//other User model methods....
    public function setActiveDirectoryAttribute($attrValue){
        $this->attributes['active_directory'] = (string) $attrValue;
    }
fahmi rizal
  • 33
  • 1
  • 7