Krish Nakum R
Krish Nakum R

Reputation: 545

How do I pass mutiple values into a query?

$s_bit=0;
$app_id="ceajecs001";

$stmtt = $this->conn->prepare("SELECT * FROM tbl_app_id WHERE app_id = ? and status = ?");  
$stmtt->bind_param("s",$app_id);    
$stmtt->bind_param("s",$s_bit); 

// i will get values into s_bit and app_id from page request
//im very new to php. i need this to complete an API for my android app.

Upvotes: 0

Views: 59

Answers (1)

Gareth Parker
Gareth Parker

Reputation: 5062

Taking a look at the manual, you're meant to make one bind_param call. As such

$stmtt->bind_param("ss",$app_id, $s_bit); 

Also, as mentioned in the comments, the first parameter is the variable types that you're passing in here. The amount of characters in that parameter have to match the number of parameters you're passing in. So here, we use two s' to say "We are passing in two strings". If we wanted to pass in two strings and an integer, we would use

$stmtt->bind_param("sis",$string1, $int1, $string2);

Not how the order of the types in the first parameter match the order of the parameters I'm passing in. According to the manual, valid types are

  • i for integer
  • d for double
  • s for string
  • b for blob

Upvotes: 2

Related Questions