yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

Convert Date object automatically to oracle's date string. #15

Closed jperelli closed 9 years ago

jperelli commented 9 years ago

It would be nice that the oci8 driver would automatically convert a date object to an oracle's date string

I was trying to insert like this

$pac = new Pac();
$pac->some_date = new DateTime();
$pac->save();

And I was receiving this error

oci_bind_by_name(): Invalid variable used for bind

After some digging, I switched the second line into this and it worked ok.

$pac->some_date = date('dd-M-Y');

It would be nice if the data type is date, to convert it to string in oci_bind_by_name.

yajra commented 9 years ago

Are you using Laravel on your example? If yes, date does automatically saved as far as I know. Also try using Carbon instead.

$pac = new Pac();
$pac->some_date = Carbon::now();
$pac->save();
yajra commented 9 years ago

Was able to replicate the issue. To fix this, you should define the dates column on your model.

class Pac extends Eloquent {

   protected $dates = ['some_date'];

}
jperelli commented 9 years ago

Sorry I was unreachable without internet for some days.

Yes I am using Laravel, but I think that it would be nicer to support dates without using carbon, just with plain php Dates.

Nevertheless, thank you very much for the support and the tip of the date column definition on the model, I'll certainly use that!

yajra commented 9 years ago

Hi,

FYI: as of Laravel-OCI8 v2.1.6, PHP's DateTime object is now supported and does not require you to specify the date fields. But I still recommend using date fields for best practice.

jperelli commented 9 years ago

Great! thanks