Q: PDO 준비 문에 와일드카드를 사용할 수 있습니까?
A: 예, PDO에서 와일드카드를 사용할 수 있습니다. 준비된 문을 사용하면 동적 값을 사용하여 강력한 데이터베이스 쿼리를 수행할 수 있습니다. 그러나 사용 방법은 표준 SQL 쿼리와 약간 다릅니다.
준비된 문에서 와일드카드를 사용하는 방법:
옵션 1:bindValue()
bindValue() 메서드를 사용하여 와일드카드가 포함된 value.
// Set the name with wildcards
$name = "%anyname%";
// Prepare the statement
$stmt = $dbh->prepare("SELECT * FROM `gc_users` WHERE `name` LIKE :name");
// Bind the name with wildcards using bindValue()
$stmt->bindValue(':name', $name);
// Execute the statement
$stmt->execute();
옵션 2:bindParam()
bindParam() 메서드 사용 와일드카드가 포함된 값을 할당하려면 바인딩하기 전에 값을 수정하세요.
// Set the name with wildcards
$name = "%anyname%";
// Prepare the statement
$query = $dbh->prepare("SELECT * FROM `gc_users` WHERE `name` like :name");
// Bind the name with wildcards using bindParam()
$query->bindParam(':name', $name);
// Execute the statement
$query->execute();
추가 참고 사항:
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3