Madrugada
Madrugada

Reputation: 1289

php bind_result

I have this sequence of code:

$connection = new mysqli('localhost','root','','db-name');
$query = "SELECT * from users where Id = ?"; 
$stmt = $connection->prepare($query); 
$stmt->bind_param("i",$id); 
$stmt->execute();
$stmt->bind_result($this->id,$this->cols);
$stmt->fetch(); 
$stmt->close(); 
$connection->close();

The problem is that the "SELECT" might give a variable number of columns, which i retain in $this->cols. Is there any possibility to use bind_result with a variable number of parameters?...or any alternative to the solution.

Upvotes: 1

Views: 2338

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157864

if you are lucky enough to run PHP 5.3+, mysqli_get_result seems what you want.

$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_array();

Upvotes: 2

Related Questions