채택완료

php로 몽고디비 조회할시 대소문자 구분업시 하는거를 적용하려는데 어떻게하면될까요??

2021-09-06 (월) 15:16:57 1,806

<?php

$model_code = $_GET['model_code'];

// required headers

header("Access-Control-Allow-Origin: *");

header("Content-Type: application/json; charset=UTF-8");

// include database file

include_once 'mongodb_config.php';

$dbname = 'product';

$collection = 'product';

//DB connection

$db = new DbManager();

$conn = $db->getConnection();

// read all records

$filter = ['model_code' => $model_code];

$option = [];

$read = new MongoDB\Driver\Query($filter, $option);

//fetch records

$records = $conn->executeQuery("$dbname.$collection", $read);

echo json_encode(iterator_to_array($records), JSON_UNESCAPED_UNICODE);

?>

위 코드로 조회하고 있습니다.

$model_code를 필터에 /^$model_code$/i 이거로 넣으면 될거같은데 문자열로 들어가져서 조회가 안됩니다

답변 2개 / 댓글 2개

채택된 답변
+20 포인트

답변에 대한 댓글 1개

/^$model_code$/i 이 방식이 Regx를 사용하는거인데 변수에 같이 넣으면 문자열로 인식되버려서 조회가 안됩니다
이렇게 해보셨어요?
$query = ['VehicleNumber' => new \MongoDB\BSON\Regex( preg_quote($arg),"i")];

답변에 대한 댓글 1개

네ㅜ 잘안되네여

답변을 작성하려면 로그인이 필요합니다.