🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۱ بهمن فلاحی
پاسخ تمرین (متدهای find، findById، update و delete)
جامعه وردپرس (برنامه نویسی) ایجاد شده در ۱۱ آبان ۱۴۰۲
    public function find(): array
    {
        $query = "SELECT * FROM {$this->userTable}";
        $results = $this->db->get_results($query, ARRAY_A);
        return $results;
    }
    public function findByID(int $ID): array
    {
        $query = $this->db->prepare("SELECT * FROM {$this->userTable} WHERE ID = %d", $ID);
        $result = $this->db->get_results($query, ARRAY_A);
        return $result;
    }    
    public function update(int $ID, array $newData)
    {
        $where = ['ID' => $ID];
        $format = ['%d'];
        $this->db->update($this->userTable, $newData, $where, $format);
    }    
    public function delete(int $ID)
    {
        $where = ['ID' => $ID];
        $format = ['%d'];
        $this->db->delete($this->userTable, $where, $format);
    }

خیلی ممنون از مشارکتتون

موفق باشین

ابوالفضل محجوب ۱۲ آبان ۱۴۰۲، ۰۳:۳۰