🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۴ دانشجوی سون‌لرن
سلام اتصال من به دیتا بیسم برقرار نمیشه
جامعه وردپرس (برنامه نویسی) ایجاد شده در ۲۰ تیر ۱۴۰۲

سلام من یه دیتا بیس ساختم به اسم 7todo ولی وصل نمیشه

زمپ هم فعاله

db = new PDO("mysql:dbname=7todo;host=localhost", 'root', '');
        } catch (PDOException $e) {
            die('Connection failed: ' . $e->getMessage());
        }
    }
    public function find($id){
        $sql = "select * from {$this->table} where {$this->primaryKey} = :id";
        $stmt = $this->db->prepare($sql);
        $stmt->execute([':id' => $id]);
        return $stmt->fetch(PDO::FETCH_OBJ);
    }
    public function update($data){
        # code for update a model
    }
    public function create($data){
        # code for create a model
    }
    public function delete($id){
        $sql = "delete from {$this->table} where {$this->primaryKey} = :id";
        $stmt = $this->db->prepare($sql);
        $stmt->execute([':id' => $id]);
        return $stmt->rowCount();
    }
}

سلام،

چه خطایی دریافت میکنید؟

کدو بصورت کامل بذارید.

محسن موحد ۲۰ تیر ۱۴۰۲، ۱۳:۳۸

abstract class  BaseModel
{
    protected $db;
    protected $table;
    protected $primaryKey = 'id';
    public function __construct()
    {
        try {
            $this->db = new PDO("mysql:dbname=7todo;host=localhost", 'root', '');
        } catch (PDOException $e) {
            die('Connection failed: ' . $e->getMessage());
        }
    }
    public function find($id){
        $sql = "select * from {$this->table} where {$this->primaryKey} = :id";
        $stmt = $this->db->prepare($sql);
        $stmt->execute([':id' => $id]);
        return $stmt->fetch(PDO::FETCH_OBJ);
    }
    public function update($data){
        # code for update a model
    }
    public function create($data){
        # code for create a model
    }
    public function delete($id){
        $sql = "delete from {$this->table} where {$this->primaryKey} = :id";
        $stmt = $this->db->prepare($sql);
        $stmt->execute([':id' => $id]);
        return $stmt->rowCount();
    }
}


Elias Alipour ۲۱ تیر ۱۴۰۲، ۰۵:۵۶

همون کدای خود اموزشه فقط دیتابیس جدید ساختم

PS C:\\xampp\\htdocs\\7Learn-PHP-Advanced-Chapter\\oop-4-principles\\Inheritance> php user.php

Connection failed: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it

خطای بالا به هنگام ران شدن تو ترمینال

Elias Alipour ۲۱ تیر ۱۴۰۲، ۰۵:۵۷

با سلام

پورت هارو در زمپ تغییر دادید ؟ اگر بله با پورت صحیح امتحان کنید

بهنام مرادی ۲۱ تیر ۱۴۰۲، ۱۰:۰۲