O
O
Optimus2016-11-28 00:02:38
PHP
Optimus, 2016-11-28 00:02:38

What to do not to write requests in the code?

A binding request in PDO looks something like this:

$q=$pdo->prepare(" INSERT INTO `table` SET data=:data, time=NOW() ");
$q->bindParam(":data",$data);
try {
    $q->execute();
} catch (PDOException $e) {
    // функция обработки ошибок
}

From a large number of requests, the code grows greatly, and try / catch write every time, too, only to produce a footcloth of code?
In this regard, questions arose:
1) What do I need a CRUD class or ORM, some kind of wrapper?
2) How to transfer data to this class / function if the data to be inserted is bound, but the tables are not bound, if they are in a variable, then you can only insert it directly into the query string directly
3) How to transfer things that are not in variables like str = str + 1 or NOW () or INTERVAL DAY () +1
In general, advise something sensible but not very fancy, otherwise some will start Doctrine ... ))
Maybe someone from independent things will advise something https:// github.com/search?l=PHP&o=desc&q=pdo+crud&...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rou1997, 2016-11-28
Pyan @marrk2

You need to see how ORM is done in frameworks like Yii2. It is not necessary to switch to a framework, but the experience is definitely worth drawing from frameworks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question