How to query in mysql with PDO concept-
Write a query in a variable.
Pass variable in conn – prepare syntax is -
$this->conn->prepare($query)
Then bind variable for where condition using function
bundParam(1,$this->id)
Finaly execute statement using function execute.
Procedure as follows –
1 . $query = “DELETE
FROM”.$this->table_name.”WHERE id = ?”;
2. $stmt =
$this->conn->prepare($query);
3. $stmt->bindParams(1,$this->id)
4. $stmt->execute()
For fetching values –
$query =
"SELECT name, price, description, category_id FROM " .
$this->table_name . " WHEREid = ?LIMIT 0,1";
$stmt =
$this->conn->prepare( $query );
$stmt->bindParam(1, $this->id);
$stmt->execute();
$row =
$stmt->fetch(PDO::FETCH_ASSOC);
$this->name =
$row['name'];
extract($row);
echo "{$name}";