Warning: mysqli_stmt :: bind_param (): Number of elements in type definition string does not match number of bind variables in /pg2.php on line 318

0

I am writing an INSERT statement and I have an error that I can not solve in the following statement:

$stmt->bind_param("$tipo_var", $insert_valores);

It happens that the variable $ var_type is enclosed in commas, so that the types of each element of the "statement" that I send to MySQL are quoted.

The real data that the system receives is:

$stmt->bind_param('iiisssssssdiiiddsssidddssssssss', 
2016, 2, 1, 'texto1', 'texto2', 'texto3', 'texto4', 'texto5', 'texto6',
'texto7', 0.01, 1, 1, 1, 0.01, 0.01, 'texto8', 'texto9', 'texto10', 11,
0.01, 0.01, 0.01, 'texto11', 'texto12', 'texto13', 'texto14', 'texto15',
'texto16', 'texto17', 'texto18')

That is, I do not find that there is a real error between the type string and the sent parameters, being that the order of each type is respected vs the variable sent.

The connection to the database and the types corresponding to each data that is sent to the database are correct, but it still gives me this error:

  

Warning: mysqli_stmt :: bind_param (): Number of elements in type definition string does not match number of bind variables in    /pg2.php on line 318

Any suggestions?

    
asked by Odnumi Oilgav 14.11.2016 в 23:59
source

3 answers

2

Finally, friends, I found out what was the drawback and I describe it for those who are going through this same problem. Almost three days fighting with the code to find that answer:

The sentence that I wrote was:

$stmt->bind_param('iiisssssssdiiiddsssidddssssssss', 
2016, 2, 1, 'texto1', 'texto2', 'texto3', 'texto4', 'texto5', 'texto6',
'texto7', 0.01, 1, 1, 1, 0.01, 0.01, 'texto8', 'texto9', 'texto10', 11,
0.01, 0.01, 0.01, 'texto11', 'texto12', 'texto13', 'texto14', 'texto15',
'texto16', 'texto17', 'texto18');

And it would really be correct, if " bind_param () " allowed pass values directly. The truth is that it is necessary to send a variable for each value that is sent, it is not possible to send the values "naked" but encapsulated within a variable.

That is, the correct way to send the sentence was:

$stmt->bind_param('iiisssssssdiiiddsssidddssssssss', $int1, $int2,
$int3, $string1, $string2, $string3, $string4, $string5, $string6,
$string7, $double1, $int4, $int5, $int6, $double2, $double3, $string8,
$string9, $string10, $int7, $double4, $double5, $double6, $string11,
$string12, $string13, $string14, $string15, $string16, $string17,
$string18);

In this way, the information was loaded into the database without any other error in the code.

Evidently it was a question of capricious syntax of this function, but that surely must keep some logic.

Thanks to those who have given me some clues and who serve those who may need it.

    
answered by 16.11.2016 в 23:35
0

There are 31 question marks, but 32 values in your parameters.

    
answered by 15.11.2016 в 00:49
0
  

Here is an example of how you can create an error report to work with statements prepare ()

With this little report you can know where the failure persists or in your sentencia SQL , ligando parametros marcadores or ejecutando sentncia .

//Sentencia prepare.
$stmt = $conexion->prepare("INSERT INTO tutabla (id,nombre,ip) VALUES (?,?,?)");

// dado que todas las operaciones siguientes necesitan un objeto de sentencia válido.
if ( false===$stmt ) {      
    exit('prepare() failed: ' . htmlspecialchars($stmt->error));
}

$rc= $stmt->bind_param("iss",$id,$nombre,$ip_adres);

//nuevamente execute () es inútil si no puedes enlazar los parámetros.      
if ( false===$rc ) {        
    exit('bind_param() failed: ' . htmlspecialchars($stmt->error));
}

$rc=$stmt->execute();

// execute () puede fallar por varias razones. Y puede ser tan estúpido como alguien trompiezo con el cable de red.
if ( false===$rc ) {
    exit('execute() failed: ' . htmlspecialchars($stmt->error));
}

$stmt->close();
  

Regarding the failure, it is telling you in English: Number of elements in the type definition chain does not match the number of variables.

    
answered by 15.11.2016 в 00:52