1

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.

1

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.