Skip to content

Instantly share code, notes, and snippets.

@riceissa
Created December 20, 2019 00:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riceissa/09638576b30132c6c7a3df83ec95ca14 to your computer and use it in GitHub Desktop.
Save riceissa/09638576b30132c6c7a3df83ec95ca14 to your computer and use it in GitHub Desktop.
testing mysql regex via php
<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