Simon
Simon

Reputation: 1406

MySQLi PHP - bind_param problem - No data supplied/Number of elements in type definition

I have an odd problem with bind_param() for mysqli in PHP.

Here's the code:

                $q = <<<SQL
INSERT INTO customers (name, company, email) 
VALUES (?, ?, ?)
SQL;

                $mysqli->QP(
                        $q,
                        "sss",
                        $this->name,
                        $this->company, $this->email);

    public function QP(string $s, string $h, $var1, ...$_): ?mysqli_result
    {
        $stmt = $this->mysqli->prepare($s);
        if (count($_) > 0) {
            $stmt->bind_param($h, $var1, $_); // line58
        } else {
            $stmt->bind_param($h, $var1);
        }

        $stmt->execute(); // line 58
        $result = $stmt->get_result();
        if ($result) {
            return $result;
        } else {
            Panic($s, $stmt->error);
        }
        return null;
    }

This function, by and large works, except in this one particular case with this query combination. I cannot use this number of variables, or more, though it looks like I can just use two variables. (?,?)

The code I inherited uses a sort of database wrapper which wraps everything up in functions and does the work, so I've tried to recreate that with bind_param by copying the header.

The number of variables passed appear to be OK, the SQL appears to be OK, the type string appears to be OK. I cannot figure out why I'm getting these two errors:

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in db.php on line 53

Fatal error: Uncaught mysqli_sql_exception: No data supplied for parameters in prepared statement in db.php on line 58

Any advice?

Upvotes: 0

Views: 18

Answers (0)

Related Questions