I am trying to make a wrapper for the select query, but I don’t understand how to pass empty variables to the functions, there is the following code:
<?php $mysqli = new mysqli("localhost", "root", "", "testdb"); $query = "SELECT id, first_name FROM test"; if ($stmt = $mysqli->prepare($query)) { $stmt->execute(); $stmt->bind_result($id, $first_name); while ($stmt->fetch()) { echo $id; echo $first_name; } $stmt->close(); } $mysqli->close(); ?> If I understand correctly:
$stmt->bind_result($id, $first_name); assigns to variables:
$id, $first_name values: id, first_name, from DB
In this example, everything works!
But how on the basis of this to make a class? Rather, I did, but how to pass variables to:
$stmt->bind_result(Сюда); Please forgive, maybe the question is stupid or not entirely clear, but I'm still learning.
The class itself, or rather the sketch:
<? class mysqliAction { public function __construct($mysqli_server, $mysqli_user, $mysqli_password, $mysqli_database) { $this->s = $mysqli_server; $this->u = $mysqli_user; $this->p = $mysqli_password; $this->d = $mysqli_database; } protected function connect() { return new mysqli($this->s,$this->u,$this->p,$this->d); } public function mysqliSelect($query) { $mysqli = $this->connect(); $stmt = $mysqli->prepare($query); $stmt->execute(); /* Определить переменные для результата */ $stmt->bind_result($id, $first_name); while ($stmt->fetch()) { echo $id; echo $first_name; } $stmt->close(); } } $mysqli = new mysqliAction($mysqli_server, $mysqli_user, $mysqli_password, $mysqli_database); $query = 'SELECT id, first_name FROM test'; $mysqli->mysqliSelect($query); ?> So everything works, but how to pass arguments to:
$stmt->bind_result($id, $first_name, и так далее);