prepare($sql); $types = implode('', array_map(function($v) { return is_int($v) ? 'i' : 's'; }, array_values($ar))); call_user_func_array(array($stmt, 'bind_param'), array_merge(array($types), array_map(function(&$v) { return $v; }, array_values($ar)))); $stmt->execute(); $stmt->close(); } $con = new mysqli('localhost', 'root', '', 'Test'); insert($con, 't1', array('f1' => 12345, 'f2' => 'X')); $con->close(); ?>