افزودن prepare به متد ها

پرسیده شده
فعالیت 970 روز پیش
دیده شده 354 بار
0

سلام 

 

منظور از اضافه کردن prepare به متد ها تقریبا یه همچین چیزی میشه ؟ 

# Read
    public function find ($id) : object
    {
        $sql = $this->connection-> get($this->table,'*', [$this->primary_key => $id]);
        $result = $this->connection->pdo->prepare($sql);
        return (object)$result ;
    }

 

و برای متد های دیگه - چون  string برنمیگردونن و متد prepare باید string دریافت کنه - اول تبدیل میکنیم به استرینگ بعد میدیم به متد prepare ؟

فایل پیوست

هادی قاسمی
هادی قاسمی

8 شهریور 00

1
حذف شده

این متد خود exec درون همین پکیجیه که دارید استفاده میکنید

public function exec(string $statement, array $map = [], callable $callback = null): ?PDOStatement
    {
        $this->statement = null;
        $this->errorInfo = null;
        $this->error = null;

        if ($this->testMode) {
            $this->queryString = $this->generate($statement, $map);
            return null;
        }

        if ($this->debugMode) {
            if ($this->debugLogging) {
                $this->debugLogs[] = $this->generate($statement, $map);
                return null;
            }

            echo $this->generate($statement, $map);

            $this->debugMode = false;

            return null;
        }

        if ($this->logging) {
            $this->logs[] = [$statement, $map];
        } else {
            $this->logs = [[$statement, $map]];
        }

        $statement = $this->pdo->prepare($statement);
        $errorInfo = $this->pdo->errorInfo();

        if ($errorInfo[0] !== '00000') {
            $this->errorInfo = $errorInfo;
            $this->error = $errorInfo[2];

            return null;
        }

        foreach ($map as $key => $value) {
            $statement->bindValue($key, $value[0], $value[1]);
        }

        if (is_callable($callback)) {
            $this->pdo->beginTransaction();
            $callback($statement);
            $execute = $statement->execute();
            $this->pdo->commit();
        } else {
            $execute = $statement->execute();
        }

        $errorInfo = $statement->errorInfo();

        if ($errorInfo[0] !== '00000') {
            $this->errorInfo = $errorInfo;
            $this->error = $errorInfo[2];

            return null;
        }

        if ($execute) {
            $this->statement = $statement;
        }

        return $statement;
    }

داخلش prepare استفاده شده و نیازی نیست خودتون prepare کنید 

 

فایل پیوست

امیر صالحی

توسط

امیر صالحی

9 شهریور 00

حذف شده
دمت گرم . این متد رو پیدا کرده بودم ولی دقیق نخونده بودم .
هادی قاسمی

9 شهریور 00

حذف شده
قربانت
امیر صالحی

9 شهریور 00

0
حذف شده

درود

این متد تو دل خودش queryها رو prepare میکنه لازم نیست همچین کار کنید

فایل پیوست

امیر صالحی

توسط

امیر صالحی

8 شهریور 00

حذف شده
توی ویدیو استاد گشتن برای این متد و پیدا نشد و گفتن خودتون پیاده سازی کنید :/
هادی قاسمی

9 شهریور 00