Bonjour,

Voila j'aimerai récupérer l'id généré par un INSERT INTO, le problème c’est que ma variable "$comm_id = $this->sql->insert_id;" me renvoi toujour la valeur zéro.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    public function insert_comment($nick, $comment_body, $ip, $tw_id, $hashtag)
    {
        require 'configuration/language/fr.php';
        $nick           = ucfirst($nick);
        $this->sql      = $this->db->prepare("INSERT INTO `comments` (nick, message, time, ip, tw_id) VALUES (?,?,?,?,?)");
        $this->time     = time();
        $this->tw_id = $this->sanitizeNumber($tw_id);
        $this->sql->bind_param('ssisi', $nick, $comment_body, $this->time, $ip, $this->tw_id);
 
        if (!$result = $this->sql->execute()) {
            die('Execute Error: (' . $this->sql->errno . ') ' . $this->sql->error);
        } else {
            $comm_id = $this->sql->insert_id;
            $this->insert_notification($this->time, $this->tw_id, $comm_id, $notifcm, $hashtag);
            header('Content-Type: application/json');
            $arr = array("status" => 'ok');
            echo json_encode($arr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
        }
    }

Merci