insert value date in informix from php using pdo

0

I have a problem when I try to make an insert of type date to my database in informix from php using pdo. I do not have problems with another type of data, I did the test with the majority For example to make an insert to this table

Create prueba1 (
cod serial,
id int,
nombre varchar(30),
fecha datetime
)

From PHP (there are 2 ways) (first define my connection)

$cona = new PDO("informix:host=10....; service=9040;database=sap2000; server=central1; protocol=onsoctcp;EnableScrollableCursors=1;CLIENT_LOCALE=en_US.CP1252;DB_LOCALE=en_US.819", "xxxxxx", "xxxxxx");
$dato1 = "(0)";
$dato2 = 333;
$dato3 = "ddddaaaannn";
$dato4 = "2016-10-19 09:10:00"

//Manera 1
    $sql1 = $cona->prepare("insert into prueba1 values ($dato1, $dato2, '".$dato3."', '".$dato4."')");
    $sql1->execute();

//Manera 2
    $sql2 = ("insert into prueba1 values ($dato1, $dato2, '".$dato3."', '".$dato4."')");
$result = $cona->query($sql2);

With either of these two forms I have no problems with the insert.

To do the same test it works from the manager of my informix database.     insert into test1 values ((0), 73, 'F000', '2016-10-19 08:10:00')

The problem is when I try to make the insert of a data type date

for example if I have a table like this

create table prueba2
(
fecha date
)

doing directly from my manager I have no problem, that is

insert into prueba2 values ('2016-10-30')

The problem is when I do the same from php

From PHP (there are 2 ways) (first define my connection)

 $cona = new PDO("informix:host=10....; service=9040;database=sap2000; server=central1; protocol=onsoctcp;EnableScrollableCursors=1;CLIENT_LOCALE=en_US.CP1252;DB_LOCALE=en_US.819", "xxxxxx", "xxxxxx");
    $dato1 = "2016-10-30";

    //Manera 1
        $sql1 = $cona->prepare("insert into prueba2 values ('".$dato1."')");
        $sql1->execute();

    //Manera 2
        $sql2 =("insert into prueba2 values ('".$dato1."')");
    $result = $cona->query($sql2);

What is it that I am doing wrong? I also tried formatting my variable date but without any results

    
asked by dante valencia92 24.10.2016 в 22:55
source

2 answers

0

If someone is of any use to you, I was able to resolve this issue with the following solution:

$dato1 = "2016/10/30";
    $sql1 = $cona->prepare("update prueba SET  prueba2= TO_DATE('".$dato1."', \"%Y/%m/%d\")");
    $sql1->execute();

I had to format it within the query. Something important is that as you see $dato1 = 2016/10/30 and the format has to be the same when it is defined in the query, if $dato1 = "2016-10-30" is to say - instead of / in the format would have to change the same.

    
answered by 07.11.2016 / 13:48
source
0

Have you tried like this?

$sql1 = $cona->prepare("insert into prueba2 values (?)");
$sql1->execute(array($dato1));

Or in this way

$sql1= $cona->prepare("insert into prueba2 values (:dato1)");
$sql1->bindParam(':dato1', $dato1);
$sql1->execute();
    
answered by 26.10.2016 в 10:11