P
P
pillson2021-08-10 08:33:59
PHP
pillson, 2021-08-10 08:33:59

Problem with PDO?

Good afternoon

Problem with PDO PHP I can't figure out what's wrong

The id_car_mark field is of type INT

The name varchar field

If you make a direct request without an alias, then everything is fine. Boolean error false

Everything comes to the argument correctly

// Получаем данные по модели
    public static function carSlug($carSlug) {
      
        $db = Db::getConnection();
        $sql = "SELECT id_car_mark from car_model where name = :myCar";

        $result = $db->prepare($sql);
        $result->bindParam(':myCar', $carSlug, PDO::PARAM_STR);
        $result->setFetchMode(PDO::FETCH_ASSOC);
        $result->execute();
        return $result->fetch();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacome, 2021-08-19
@Jacome

instead
of $result->bindParam(':myCar', $carSlug, PDO::PARAM_STR);
try
$result->bindParam('myCar', $carSlug, PDO::PARAM_STR);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question