I'm using PHP 5.6.16 accessing MongoDB 3.2 via the MongoDB driver for PHP (php_mongo-1.6.14-5.6-ts-vc11-x64), and I've already been able to create a few pages.
I need to create a page that lists the employees registered in MongoDB from a text entered by the user, for example, the first name (the name field in MongoDB stores the full name).
Using the mongoshell, I can execute this query in the following command
db.employee.find("name":/Rogerio/)
If I try to pass the full name as a parameter, logically the search works (see full PHP code below).
<?php
$m = new MongoClient("mongodb://localhost:27017");
$collection = $m->mydb->employees;
echo "<form action='' method=post>";
echo "<input type='text' name='name'>";
echo "<input type=submit name=search value=Search>";
echo "</form>";
if (isset($_POST['search'])){
$name = $_POST['name'];
$employees = $collection->find(array('name' => $name));
echo "<table border=0 rules=rows width=600>";
foreach ($employees as $emp){
echo "<tr>";
echo "<td>{$emp['nome']}</td>";
echo "</tr>";
}
echo "</table>";
}
?>
To be able to search for a part of the name, I tried to use the following code to set $name:
$name = "/" . $_POST['name'] . "/";
but it did not work.
How to pass this kind of parameter to the PHP driver?