Prepared params LIKE statement Not working with SQLSRV

后端 未结 2 1372
刺人心
刺人心 2021-01-23 12:59

I am using SQLSRV 3.0 for PHP and working against a MSSQL2008.

My problem I am having, is that I can\'t get a LIKE statement in the query to work?

$conne         


        
相关标签:
2条回答
  • 2021-01-23 13:33

    Try to do this:

    $strSQL = "SELECT * FROM tbl WHERE col2 like '%' + CONVERT(NVARCHAR, ?) + '%' or col2 like '%' + CONVERT(NVARCHAR, ?) + '%' ";
    
    $searchTerm = "<<some multibye characters>>";
    
    $searchTerm = iconv('utf-8', 'utf-16le', $searchTerm);
    
    $params = array( array($searchTerm, NULL, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY)));
    
    0 讨论(0)
  • 2021-01-23 13:48

    Adjust your code to the following:

    $sql = "select * from tbl where col2 LIKE ? or col2 LIKE ?";
    $params = array($sID."%", $sUser."%");
    $stmt = sqlsrv_query( $conn, $sql, $params);
    
    0 讨论(0)
提交回复
热议问题