반응형
MySQL 빈 집합의 동작 오류
저는 MariaDb와 PHP7을 사용하고 있는데 왜 항상 잘못된 결과가 나오는지 궁금합니다.MySQL 스키마와 데이터 삽입 스크립트입니다.
CREATE TABLE IF NOT EXISTS `BB_Orders`(
`row_id` INT PRIMARY KEY AUTO_INCREMENT,
`order_id` VARCHAR(255) NOT NULL DEFAULT ''
)
INSERT INTO `BB_Orders`(`row_id`, `order_id`) VALUES(1, '190061603-A')
INSERT INTO `BB_Orders`(`row_id`, `order_id`) VALUES(2, '190604470-A')
INSERT INTO `BB_Orders`(`row_id`, `order_id`) VALUES(3, '191206232-A')
INSERT INTO `BB_Orders`(`row_id`, `order_id`) VALUES(4, '191269277-A')
여기 내 PHP 함수 정의가 있습니다.
function ROWExists($Con, $TableName, $Condition){
$RowID=0;
$SelectStatement = "SELECT `row_id` FROM `".$TableName."` WHERE ";
foreach($Condition as $CKey=>$CValue){
$SelectStatement.="TRIM(`".$CKey."`)=TRIM('".$CValue."') AND ";
}
$SelectStatement=rtrim($SelectStatement, ' AND ');
$SelectStatement.=" LIMIT 1;";
echo 'SELECT STATEMENT: '.$SelectStatement.PHP_EOL;
echo $SelectStatement.PHP_EOL;
$Resultset=mysqli_query($Con, $SelectStatement);
if(!empty($Resultset)){
if($Resultset->num_rows){
while($Result=mysqli_fetch_assoc($Resultset)){
if(!empty($Result)){
$RowID=$Result['row_id'];
}
}
}
}
return $RowID;
}
이 함수를 다음과 같이 부릅니다.
$RowID=ROWExists($Con, 'BB_Orders', array('order_id'=>'190061603-A'));
//returns the 'row_id' correct
$RowID=ROWExists($Con, 'BB_Orders', array('order_id'=>'190061603-Z'));
//returns the 'row_id' incorrect, this should have been 0, but not
언급URL : https://stackoverflow.com/questions/49009285/mysql-empty-set-misbehavior
반응형
'programing' 카테고리의 다른 글
마리아에서 열 이름 변경DB (0) | 2023.01.17 |
---|---|
mysql error 1364 필드에 기본값이 없습니다. (0) | 2023.01.17 |
Vuex store state : 싱글샷에서 상태 값을 재설정하기 위한 변수와 함수를 혼합하는 방법 (0) | 2022.11.23 |
JavaScript에서 "arguments" 개체를 배열로 변환하려면 어떻게 해야 합니까? (0) | 2022.11.23 |
무중단 새로고침 시 Vuex 모듈 상태가 업데이트되지 않음 (0) | 2022.11.23 |