Answer the question
In order to leave comments, you need to log in
Why does execute return false?
Hello. I took a Zinchenko course here, maybe someone knows, everything was fine and clear until the middle of the last lesson, the createProduct method returns false
public static function createProduct($options)
{
// Соединение с БД
$db = Db::getConnection();
// Текст запроса к БД
$sql = 'INSERT INTO product '
. '(name, code, price, category_id, brand, availability,'
. 'description, is_new, is_recommended, status)'
. 'VALUES '
. '(:name, :code, :price, :category_id, :brand, :availability,'
. ':description, :is_new, :is_recommended, :status)';
// Получение и возврат результатов. Используется подготовленный запрос
$result = $db->prepare($sql);
$result->bindParam(':name', $options['name'], PDO::PARAM_STR);
$result->bindParam(':code', $options['code'], PDO::PARAM_STR);
$result->bindParam(':price', $options['price'], PDO::PARAM_STR);
$result->bindParam(':category_id', $options['category_id'], PDO::PARAM_INT);
$result->bindParam(':brand', $options['brand'], PDO::PARAM_STR);
$result->bindParam(':availability', $options['availability'], PDO::PARAM_INT);
$result->bindParam(':description', $options['description'], PDO::PARAM_STR);
$result->bindParam(':is_new', $options['is_new'], PDO::PARAM_INT);
$result->bindParam(':is_recommended', $options['is_recommended'], PDO::PARAM_INT);
$result->bindParam(':status', $options['status'], PDO::PARAM_INT);
if ($result->execute()) {
// Если запрос выполенен успешно, возвращаем id добавленной записи
return $db->lastInsertId();
}
// Иначе возвращаем 0
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question