Property Foyer Property Foyer - 2 months ago 11
PHP Question

Warning: mysqli_stmt_bind_param: Number of elements in type definition string doesn't match number of bind variables

I am getting the message “


Warning: mysqli_stmt_bind_param: Number of elements in type definition string doesn't match number of bind variables in…


in a simple php select statement

$wherePtest1 = "postcode= ? AND proptype = ? AND ";
$whereVtest1 = "$lc_postcode, $proptype";

$where_no_andP = rtrim($wherePtest1, 'AND ');
var_dump($where_no_andP);
var_dump($whereVtest1);

/* 1. create a prepared statement */
if ($stmt1 = mysqli_prepare($link, "SELECT $what_select4TS FROM $table WHERE $where_no_andP ORDER BY rent $reihenach LIMIT $offset, $rowsPerPage"))
{
/* 2. bind parameters for markers */
mysqli_stmt_bind_param($stmt1, "ss", $whereVtest1);

/* 3. execute query */
etc


I am getting this warning EVEN THOUGH
var_dump()
correctly show

string(29) "postcode= ? AND proptype = ?"
string(9) "da8, Flat"!

Answer

Because this:

mysqli_stmt_bind_param($stmt1, "ss", $whereVtest1);
                                           ^^

MySQLi will NOT take your CSV data in $whereVtest1 and split it up for you. You have to eXPLICITLY provide a SINGLE value for EVERY placeholder you have:

mysqli_stmt_bind_param($stmt1, 'ss....s', $val1, $val2, .... $valN);
                                ^----------^
                                 ^------------------^
                                      ^------------------------^