簡體   English   中英

如何在 PHP 中通過 CQL(Cassandra DataStax PHP DRIVER)修改或替換包含“LIKE”和“bindValue”的 SQL 查詢?

[英]How to modify or replace in PHP my SQL query containing "LIKE" and "bindValue" by CQL (Cassandra DataStax PHP DRIVER)?

尋找如何在 CQL 查詢中執行LIKE (使用以下 Cassandra PHP 驅動程序: https ://github.com/datastax/php-driver)替換我的以下 SQL 代碼:

    $con->execute("CREATE TABLE IF NOT EXISTS images(siteUrl varchar PRIMARY KEY, imageUrl varchar, alt varchar, title varchar, description varchar, 
                    keywords varchar, textFromWebPage varchar, site_lang varchar, width_of_image float, height_of_image float, image_type varchar, 
                    image_extension varchar, image_attribute varchar, clicks bigint, broken int, centroidScore float, graphBasedScore float, scrapeScore float, 
                    centroidWeightedScore float, created_date timestamp) WITH caching='ALL';");
        
        $con->execute("CREATE CUSTOM INDEX images_prefix ON images(siteUrl, alt, title, keywords, description, textFromWebPage) USING 'org.apache.cassandra.index.sasi.SASIIndex'");
        
    
        $query = $this->con->prepare("SELECT * 
                                        FROM images 
                                            WHERE (title LIKE :term 
                                            OR alt LIKE :term 
                                            OR siteUrl LIKE :term 
                                            OR keywords LIKE :term 
                                            OR description LIKE :term
                                            OR textFromWebPage LIKE :term
                                            AND broken=0 ORDER BY clicks DESC LIMIT :fromLimit, :pageSize");
        
                    $searchTerm = "%". $term . "%";
                    $query->bindValue(":term", $searchTerm);
                    $query->bindValue(":fromLimit", $fromLimit, PDO::PARAM_INT);
                    $query->bindValue(":pageSize", $pageSize, PDO::PARAM_INT);
                    $query->execute();
        
                    $resultsHtml = "<div class='imageResults'>";
        
                    $count = 0;
                    
                    while($row = $query->fetch(PDO::FETCH_ASSOC)) {
                         ...
                         ...
                    }

我在以下 DataStax 文檔鏈接上看到了這一點: https://docs.datastax.com/en/dse/5.1/cql/cql/cql_using/useSASIIndex.html ,它需要執行CREATE CUSTOM INDEX來創建前綴相關表並指定必須發出LIKE請求的列。 但就我而言,我需要將LIKE查詢應用於images表的多列。

那么我如何修改我上面的代碼,以便它正確適應 DataStax 的 CASSANDRA PHP 驅動程序,知道最初它是我試圖用 CQL 替換的 SQL,並且它首先包含一個bindValue ???

請幫幫我,因為這讓我頭疼了幾個小時。

這些行不需要引號,字符串類型 PARAM 綁定就足夠了(見下文):

OR strcmp(soundex(title), soundex(:shorterm)) = 0
OR strcmp(soundex(alt), soundex(:shorterm)) = 0)
OR strcmp(soundex(siteUrl), soundex(:shorterm)) = 0
OR strcmp(soundex(keywords), soundex(:shorterm)) = 0
OR strcmp(soundex(description), soundex(:shorterm)) = 0
OR strcmp(soundex(description), soundex(:shorterm)) = 0

您已將參數定義為字符串。

$query->bindValue(":term", $searchTerm, PDO::PARAM_STR);
$query->bindValue(":shorterm", $term, PDO::PARAM_STR);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM