L
L
littleguga2015-02-20 02:54:59
PHP
littleguga, 2015-02-20 02:54:59

How to process SQL query correctly?

Good day to all!
There is

$id = mysql_result($res,0,"id") or die(mysql_error());

0 can also be returned from the base, but die(mysql_error()) is selected in this one. How to avoid this and correctly handle 0 if it was given to the database?
Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2015-02-20
@littleguga

Some people say that I'm nervous.
Well, how can you not be nervous when you see such a monkey * code, the focus of sin and vice?
Well, how can you manage to make SO many mistakes in one line?
Guga, my boy. If you continue to write all this, then you will go to hell.
Here, see how to actually process the SQL query correctly:

$stmt = $pdo->prepare("SELECT id FROM users WHERE email =?");
$stmt->execute([$email]);
$id = $stmt->fetchColumn();

-----
* from the word "monkey", i.e. repeating certain actions without understanding their meaning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question