S
S
Sasha Brahms2015-11-20 13:27:27
PHP
Sasha Brahms, 2015-11-20 13:27:27

How do you know if a PDO request is successful?

How to understand if the request to the database was successful, PDO?
execute() - always returns true or an exception...
mb RowCount() > 0 - lucky, right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Ernest Faizullin, 2015-11-20
@Dlike

try {
    $res->execute();
} catch (Exception $e) {
    die("Ошибка");
}

// нет ошибки...

A
Adamos, 2015-11-20
@Adamos

UPDATE table SET field='new_value' WHERE field='old_value'

If there are no rows in the table where field='old_value', then RowCount() will return 0 even if the query was successful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question