Hello stackoverflow ,
SO , I've been trying to display some values in my MYSQLI database using oop in php but unable to do it.
Please how do i do it ?
Thanks
This is the way to do it simply
$searchSql = "SELECT * FROM countries WHERE name = ?";
$Connection = "your mysql connection" ; // ex: in CI : $this->db->conn_id
$stmt = $Connection->prepare($searchSql);
$stmt->bind_param("s", "name_for_search");
$ok = $stmt->execute();
$result = $stmt->get_result();
$data = $result->fetch_all(MYSQLI_ASSOC);
To use PDO is apparently the best way to display data from MySQL database using OOP in PHP
$stmt = $Connection->prepare("SELECT * FROM countries WHERE name = ?");
$stmt->execute(["name_for_search"]);
$data = $stmt->fetchAll();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.