Created
September 18, 2019 15:35
-
-
Save mnvx/616d84801aaa4db5fbeb0bad5df85876 to your computer and use it in GitHub Desktop.
pdo_pgsql test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//////////////////////////////////// Returns 0 records | |
$pdo = new \PDO('pgsql:host=localhost;dbname=postgres', 'postgres', 'postgres'); | |
$sql = <<<SQL | |
SELECT * | |
FROM ( | |
SELECT 'CHAC TECHNOLOG*' as alias | |
UNION | |
SELECT 'KINDERY LIGHTING SALES DE?T*' | |
) m | |
JOIN ( | |
SELECT 'CHACTECHNOLOGICO\\' as ie_clean | |
UNION | |
SELECT 'KINDERYLIGHTINGSALESDEPT' as ie_clean | |
) t ON t.ie_clean ILIKE REPLACE(REPLACE(REPLACE(m.alias, '*', '%'), ?, '_'), ' ', '') | |
ORDER BY ie_clean; | |
SQL; | |
echo $sql . PHP_EOL . PHP_EOL; | |
$stmt = $pdo->prepare($sql); | |
$stmt->execute(['?']); | |
print_r($stmt->fetchAll(\PDO::FETCH_ASSOC)); | |
//////////////////////////////////// Returns 2 records | |
$pdo = new \PDO('pgsql:host=localhost;dbname=postgres', 'postgres', 'postgres'); | |
$sql = <<<SQL | |
SELECT * | |
FROM ( | |
SELECT 'CHAC TECHNOLOG*' as alias | |
UNION | |
SELECT 'KINDERY LIGHTING SALES DE?T*' | |
) m | |
JOIN ( | |
SELECT 'CHACTECHNOLOGICO' as ie_clean | |
UNION | |
SELECT 'KINDERYLIGHTINGSALESDEPT' as ie_clean | |
) t ON t.ie_clean ILIKE REPLACE(REPLACE(REPLACE(m.alias, '*', '%'), ?, '_'), ' ', '') | |
ORDER BY ie_clean; | |
SQL; | |
echo $sql . PHP_EOL . PHP_EOL; | |
$stmt = $pdo->prepare($sql); | |
$stmt->execute(['?']); | |
print_r($stmt->fetchAll(\PDO::FETCH_ASSOC)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment