I only know the method to create the data structure(array or object) from the table:
$results=$pdo->query("SELECT * FROM user");
$rows=$results->fetch(PDO :: FETCH_ASSOC);

But what if I want to take a single element, which method can I insert instead of"???" to return the string?
$result=$pdo->query(" SELECT name FROM user WHERE id=2");
$row=$results->???;
  • Only this way:
    $result=$pdo->query("SELECT name FROM user WHERE id=2");
    $row=$results->fetch(PDO :: FETCH_ASSOC)['name'];
    – Nuclear86 Jul 14 '19 at 15:07

1 Answers 1

PDOStatement :: fetch- get the following line
PDOStatement :: fetchAll - get all strings

You need to put things in order in terminology.What is the"make up a data structure from a table"? What is a"single item"? There are three entities: tables, rows and columns, and operate them.

I only know the method to create the data structure(array or object) from the table:
 $results=$pdo->query("SELECT * FROM user");
$rows=$results->fetch(PDO :: FETCH_ASSOC);
You are mistaken, there will be only one row in $rows, not all.