Created
December 20, 2019 00:36
-
-
Save riceissa/09638576b30132c6c7a3df83ec95ca14 to your computer and use it in GitHub Desktop.
testing mysql regex via php
This file contains 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
<pre> | |
<?php | |
include_once("backend/globalVariables/passwordFile.inc"); | |
$queriesList = array( | |
'select "Ought" regexp ?' => 1, | |
'select "Forethought" regexp ?' => 0, | |
'select "Forethought|Ought" regexp ?' => 1, | |
'select "Open Phil|Ought" regexp ?' => 1, | |
'select "Open Phil|Ought|MIRI" regexp ?' => 1, | |
'select "Open Phil|ForethOught|MIRI" regexp ?' => 0, | |
'select "Ought Phil|ForethOught|MIRI" regexp ?' => 0, | |
'select "Ought|Phil|ForethOught|MIRI" regexp ?' => 1, | |
'select "nOught|ForethOught|MIRI" regexp ?' => 0, | |
'select "nOught|ForethOught|Ought|MIRI" regexp ?' => 1, | |
); | |
foreach ($queriesList as $query => $answer) { | |
$stmt = $mysqli->prepare($query); | |
$donee = "Ought"; | |
$exactMatchDoneeRegex = '(^|\\|)'.$donee.'(\\||$)'; | |
$stmt->bind_param("s", $exactMatchDoneeRegex); | |
$stmt->execute(); | |
$result = $stmt->get_result(); | |
$row = $result->fetch_assoc(); | |
if (array_values($row)[0] === $answer) { | |
echo "success!" . "\n"; | |
} else { | |
echo "fail!" . "\n"; | |
} | |
} | |
?> | |
</pre> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment