


PHP PDO プリペアド ステートメントで「SQLSTATE[HY093]: Invalid Parameter Number」がスローされるのはなぜですか?
PHP PDOException: "SQLSTATE[HY093]: 無効なパラメータ番号"
PHP PDOException のデバッグは、特に次の場合に困難になることがあります。 「SQLSTATE[HY093]: 無効なパラメータ番号」が発生しました エラー。このエラーは、多くの場合、プリペアド ステートメントでの名前付きパラメータの誤った使用を示します。
次の PHP コードを考慮してください:
function add_persist($db, $user_id) { $hash = md5("per11".$user_id."sist11".time()); $future = time()+(60*60*24*14); $sql = "INSERT INTO persist (user_id, hash, expire) VALUES (:user_id, :hash, :expire) ON DUPLICATE KEY UPDATE hash=:hash"; $stm = $db->prepare($sql); $stm->execute(array(":user_id" => $user_id, ":hash" => $hash, ":expire" => $future)); return $hash; }
この関数を実行すると、エラー「SQLSTATE[HY093]: Invalid」が発生します。パラメータ番号」が発生する可能性があります。根本的な原因は、execute() メソッドが呼び出される行にあります。具体的には、ON DUPLICATE KEY UPDATE hash=:hash 句は、挿入操作と更新操作の両方に同じパラメータ名「:hash」を使用します。
この問題を解決するには、一意のパラメータ名を指定する必要があります。 update句のハッシュ値。修正されたコードは次のとおりです。
$sql = "INSERT INTO persist (user_id, hash, expire) VALUES (:user_id, :hash, :expire) ON DUPLICATE KEY UPDATE hash=:hash2"; $stm->execute( array(":user_id" => $user_id, ":hash" => $hash, ":expire" => $future, ":hash2" => $hash) );
update 句のハッシュ値に一意のパラメータ名「:hash2」を指定すると、「SQLSTATE[HY093]: パラメータ番号が無効です」エラーが解決されます。これにより、PDO ドライバーが準備された SQL ステートメントにパラメーターを正しくマップできるようになります。
以上がPHP PDO プリペアド ステートメントで「SQLSTATE[HY093]: Invalid Parameter Number」がスローされるのはなぜですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

todropaviewinmysql、 "dropviewifexistsview_name;" andtomodifyaviewを使用して、 "createorreplaceviewview_nameasselect ..."を使用します

mysqlviewscanefectiveativeativeizedesignpatternslikeadapter、decorator、factory、andobserver.1)adapterpatternadaptsdatafromdifferenttablesintoaunifiedview.2)decoratorpatternenhancesdatawithedfieldsfieldsiffieldsiffieldsiffiedを

viewsinmysqlarebenefentialforsimprifiningcomplexqueries、拡張セキュリティ、ダタコンシーニング、および最適化されたパフォーマンスを保証する1)itsmplifyififycomplexqueriesbyencapsulsingthemintoreusableviews.2)viewsencurationecuritybycontrollingcescesces.3)

to CreateAsimpleviewinmysql、usethecreateviewstatement.1)DefinetheTheTheThecreateview_nameas.2)SpecifyTheSelectStatementtatementtatementtatementtatementtatementtatementedeSireddata.3)

tocleateusersinmysql、usethecreateuserstatement.1)foralocaluser:createUser'localuser '@' localhost'identifidedifiedifiedified 'securepassword';

mysqlviewshavelimitations:1)supportallsqloperations、制限、dataManipulationswithjoinsorubqueries.2)それらは、特にパフォーマンス、特にパルフェクソルラージャターセット

reperusermanmanagementInmysqliscialforenhancingsecurationsinginuring databaseaperation.1)usecreateusertoaddusers、指定connectionsourcewith@'localhost'or@'% '。

mysqldoes notimposeahardlimitontriggers、しかしpracticalfactorsdeTerminetheireffectiveuse:1)serverconufigurationStriggermanagement; 2)complentiggersincreaseSystemload;


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

WebStorm Mac版
便利なJavaScript開発ツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 中国語版
中国語版、とても使いやすい

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール
