0
0

More than 1 year has passed since last update.

PHP - mysqli prepare のエラー ( Fatal error: Uncaught ArgumentCountError: The number of elements in the type definition string must match the number of bind variables )

Last updated at Posted at 2023-01-05

ポイント

prapare の第一引数には bind するパラメータの型を文字列で渡すこと

string 二個なら ss
string と integer なら si

というように

コード例

巷の例に出てくる sss とか ってなんだよと思いながらてきとうに指定していたらエラーが起こり続けていた

<?php

$mysqli = new mysqli('localhost', 'root', '', 'example');

$stmt = $mysqli->prepare("INSERT INTO users(id, name) VALUES (?, ?)");

// $stmt->bind_param('sss', $id, $name); # エラー
$stmt->bind_param('is', $id, $name); # integer と string なので 第一引数は is

$id = 2;
$name = "ABC";

$stmt->execute();

参考

image

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0