Question

I am trying to get this script to run, but I fail on a very simple stupid thing that has kept me getting further for the past 2 hours. I have written a PDO statement in a function of a class that inserts a bunch of integers in a mysql db. If I call on the function from a file using

$result->createResult(0, 0, 0,0,0,0,0,"1234",0);

it does not work. If I use

$result->createResult(1, 1, 1,1,1,1,1,"1234",1);

it runs just fine! the function that created the mysql entry is

 public function createResult($id, $pp_id, $i_id, $ii_id, $cs_id, $ed_id, $em_id, $l_id, $ud_id){

    if ($this->databaseConnection()) {
            $query_new_result_insert = $this->db_connection->prepare('INSERT INTO results (id, pp_id, i_id, ii_id, cs_id, ed_id, em_id, l_id, ud_id, created_at) VALUES(:id, :pp_id, :i_id, :ii_id, :cs_id, :ed_id, :em_id, :l_id, :ud_id, now())');
            $query_new_result_insert->bindValue(':id', $id, PDO::PARAM_INT);
            $query_new_result_insert->bindValue(':pp_id', $pp_id, PDO::PARAM_INT);
            $query_new_result_insert->bindValue(':i_id', $i_id, PDO::PARAM_INT);
            $query_new_result_insert->bindValue(':ii_id', $ii_id, PDO::PARAM_INT);
            $query_new_result_insert->bindValue(':cs_id', $cs_id, PDO::PARAM_INT);
            $query_new_result_insert->bindValue(':ed_id', $ed_id, PDO::PARAM_INT);
            $query_new_result_insert->bindValue(':em_id', $em_id, PDO::PARAM_INT);
            $query_new_result_insert->bindValue(':l_id', $l_id, PDO::PARAM_STR);
            $query_new_result_insert->bindValue(':ud_id', $ud_id, PDO::PARAM_INT);

            $query_new_result_insert->execute();
    }
}

this seems to crash on 0 values. if I check (empty($i_id)) it returns true. I can't get my head around this! Could anyone be so kind to help?

Was it helpful?

Solution

Ok, I finally figured it out... It wasn't the table structure, but the empty check... empty returns true on value 0 as described here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top