I got this error-message:

Fatal error: Uncaught ArgumentCountError: The number of elements in the type definition string must match the number of bind variables in /var/www/html/soma/doku_functions.php:600 Stack trace: #0 /var/www/html/soma/doku_functions.php(600): mysqli_stmt->bind_param() #1 [...]

final query, bind types and variables:

SQL-Query:
SELECT * FROM `Doku` WHERE `Doku`.`beginn` >= ? AND `Doku`.`beginn` < ? AND `Doku`.`user` = ? AND `Doku`.`klient` = ? ORDER BY `Doku`.`vID`, `Doku`.`beginn`, `Doku`.`ende`;  
Type definition String: "iiii"  
Bind Variables:
integer: 1643670000  
integer: 1646089200  
integer: 6  
integer: 9 

on that PHP-Code (8.0.8):

    $sql = "SELECT * FROM `Doku` WHERE `Doku`.`beginn` >= ? AND `Doku`.`beginn` < ? "; //'".$start."' '".$ende."'
    $bindlist = array((int)$start, (int)$ende); $bindparams = "ii";
    $seeHours = (string)implode(',', $recht->myRight('seeHours'));

    if ( (int)$user > 0 ) 
    { 
        $sql .= "AND `Doku`.`user` = ? "; //'".$user."'
        $bindlist[] = (int)$user; 
        $bindparams .= "i";
        if ( !$recht->hasRightFor($_SESSION['id'], 'seeHours', $user) ) exit;
    } 
    else 
    { 
        $sql .=  "AND `Doku`.`user` IN (?) "; 
        $bindlist[] = $seeHours;  
        $bindparams .= "s";  //".$seeHours."
    }
    if ( $klient == 0 OR $klient == "" ) 
    { 
        $sql .= " ORDER BY `Doku`.`beginn`, `Doku`.`ende`;"; 
    }
    else 
    { 
        $sql .= "AND `Doku`.`klient` = ? "; $sql .= "ORDER BY `Doku`.`vID`, `Doku`.`beginn`, `Doku`.`ende`;"; 
        $bindlist[] = (int)$klient;  
        $bindparams .= "i";  //'".$klient."'
    }
    echo "<br>SQL-Query: <br>".$sql;
    include 'dbconnect.php';
    
    echo "<br>Type definition String: \"".$bindparams."\"";
    echo"<br>Bind Variables: ";
    foreach ( $bindlist as $p ) echo "<br>".gettype($p).": ".$p;
    $stmt = $conn->prepare($sql); 
    $stmt->bind_param($bindparams, $bindlist);
    $stmt->execute();
    $result = $stmt->get_result(); 
    $assoc = $result->fetch_assoc(); 

I counted 4, I counted many times, now I count on you...

Following Your Common Sense and gview , I changed the code to:

    
    echo "<br>Type definition String: \"".$bindparams."\"";
    function dotty($a, $b, $c, $d) 
    {
        echo " Bind Variables: ";
        echo "<br>dottyfied: ".$a."|".$b."|".$c."|".$d."|";
    }
    echo "<br>".count($bindlist);
    dotty(...$bindlist);
    $stmt = $conn->prepare($sql); 
    $stmt->bind_param($bindparams, ...$bindlist);
    

resulting in:

Type definition String: "iiii"  
4 Bind Variables:  
dottyfied: 1643670000|1646089200|1|1|  

Fatal error: Uncaught ArgumentCountError: The number of variables must match the number of parameters[...]

I'll give a try to Dharman's advice, but it will take some microseconds...

0

There are 0 best solutions below