-1
こんにちは私はウェブサイトを作成していますが、dbからアイテムを選択するためのカスタム関数を作成したいのですが、私の問題は解決できません。dbから項目を選択する汎用関数を作成する
function select($select, $from, $where, $item)
{
global $db;
if ($where != "")
{
$pdoselect = $db->prepare("select :select from :from where :where = :where2");
$pdoselect->bindParam(":select", $select);
$pdoselect->bindParam(":from", $from);
$pdoselect->bindParam(":where", $where);
$pdoselect->bindParam(":where2", $item);
$pdoselect->execute();
foreach ($pdoselect as $return)
{
echo $return[" . $select . "];
}
} else {
$pdoselect = $db->prepare("select :select from :from");
$pdoselect->bindParam(":select", $select);
$pdoselect->bindParam(":from", $from);
$pdoselect->execute();
foreach ($pdoselect as $return)
{
echo $return[" . $select . "];
}
}
}
あなたのクエリには ':'で始まるプレースホルダはありませんので、 'bindParam'呼び出しはどのようなものでしょうか? – Barmar
テーブル名に ':placeholder'を使用することはできません。リテラル値を使用できる場所でのみ使用できます。 – Barmar
私はそれを編集しました。申し訳ありません –