A
A
Aptop2014-11-25 14:51:01
Doctrine ORM
Aptop, 2014-11-25 14:51:01

What is the correct way to use doctrine DBAL?

According to the documentation (selection)
1.
$sql = "SELECT * FROM users WHERE name = :name OR username = :name";
$stmt = $conn->prepare($sql);
$stmt->bindValue("name", $name);
$stmt->execute();
2. $stmt = executeQuery("SELECT * FROM users WHERE name = :name OR username = :name", [":name" => $name]);
There was a slight difficulty. When using Phpstorm, the second method is crossed out with a note that the method is marked as Internal
AND the dockblock states that
PERF: Directly prepares a driver statement, not a wrapper.
What does this mean? Which is better to use the first approach?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Benkovsky, 2014-11-25
@Aptop

This means that you are using an internal library method that should not be used anywhere other than the library itself. It follows from this that for most tasks you have public methods that you should use (see Sergey Senkevich 's answer )
Regarding your question "How to use doctrine DBAL correctly?" I can answer exactly: dbal is translated as the abstract level of the database, and you put native sql queries into it ... why then use dbal?....
Read doctrine2 docs / examples and life will become much easier.

S
Sergey Senkevich, 2014-11-25
@ssenkevich

Most likely you forgot $conn->

$stmt = $conn->executeQuery(
    "SELECT * FROM users WHERE name = :name OR username = :name",
    [":name" => $name]
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question