P
P
Pavel2017-12-13 22:59:43
PHP
Pavel, 2017-12-13 22:59:43

How to get rid of duplicate output values ​​of a PDO::query() query?

Good afternoon. I am learning PHP and MariaDB stack. There is the following code for accessing the database:

$db = new PDO('mysql:host=localhost;dbname=taxi', 'root', '123');
$sql = 'SELECT * FROM autos WHERE id = 1';
$result = $db->query($sql);
$arr = $result->fetch();
var_dump($arr);

var_dump returns the following result:
5a3185b89dc5f656507347.png
As you can see, each underlined line duplicates the values ​​of the previous one, but with a through indexing. Is there any way to get rid of this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2017-12-13
@Pavel333

$result = $db->query($sql, PDO::FETCH_ASSOC);

D
Don Gan, 2017-12-13
@PravdorubMSK

just need to use wrappers under mysql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question