0

I have this function

  // check params
  if( !is_array($params)){
    die("iDB.get_rows_with_params: invalid parameter $params.");
  }
  if( count($params) < 1){
    die("iDB.get_rows_with_params: invalid params size.");
  }

  $sql = "SELECT " . $fields . " FROM " . $tbl;
  $types='';
  $where='';
  $array_size = count($params);
  for($i=0; $i <$array_size; $i++){
    if( $where == '' ){
      $where = $params[$i][0].'=?';
    } else {
      $where .= ' AND ' . $params[$i][0].'=?';
    }
    $types .= $params[$i][1];

  }
  $sql .= ' WHERE ' . $where;
  echo $sql;
      die();    
}

with $params being an array in this format

(print_r):
Array ( 
    [0] =>
    Array ( [0] => username 
            [1] => s 
            [2] => lsa@luisabreu.pt )
    [1] => 
    Array ( [0] => password 
            [1] => s 
            [2] => 2fb14688f648976df0f59fb143370d1c 
) )

How can I use this array to bind parameters (username and password in this case but can be anything) once I can only call mysqli_stmt_bind_param one time. I know this is not very detailed but I'll be glad to answer everything.

Machavity
  • 30,841
  • 27
  • 92
  • 100
  • Since it looks like the column name is `username` why do you need to run a loop? What are you doing with `$types`? I'm going to have to assume you execute your prepare? – StackSlave Jun 28 '16 at 00:11
  • Duplicate of http://stackoverflow.com/questions/17870999/bind-multiple-parameters-into-mysqli-query – Tomaso Albinoni Jun 28 '16 at 00:18
  • not yet executing. still trying to prepare sql. username in this case but can be anything. trying to build a generic function that prepares any sql. $types will be the 2nd param to mysqli_stmt_bind_param – Luís Abreu Jun 28 '16 at 00:30

0 Answers0