0

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?

bolvo
  • 361
  • 3
  • 13
  • can you show your table structure? – CodeBird Apr 16 '14 at 20:38
  • If it "crashes", execute would throw an error or return boolean false. try `if (!$...->execute()) { die($this->db_connection->error_info); }` or whatever instead. – Marc B Apr 16 '14 at 20:39
  • 5
    It is likely your tables, where in the structure "NULL" is set to "no" – Daniel Apr 16 '14 at 20:39
  • "it does not work" ... please elaborate – nl-x Apr 16 '14 at 20:41
  • check out this: http://stackoverflow.com/questions/3726505/how-to-squeeze-error-message-out-of-pdo to see how to make PDO show errors – CodeBird Apr 16 '14 at 20:43
  • @Daniel, since he is not sending any "NULL", that is probably not the case. He is probably running into constraints of foreign keys. But first, let him tell us what the problem really is. Is it just not inserting? Is it returning an error? Is his computer generating smoke? – nl-x Apr 16 '14 at 20:47
  • @nl-x - hahaha .. Probably the indian making digital smoke signals. He is applying integers, so that is seen as NULL. – Daniel Apr 16 '14 at 21:25

1 Answers1

0

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

Community
  • 1
  • 1
bolvo
  • 361
  • 3
  • 13