1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| <?php
public function magicQuotesAntidote()
{
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
$strip = function(&$value, $pKey) { stripslashes($value); };
if (isset($_GET))
{
array_walk_recursive($_GET, $strip);
}
if (isset($_POST))
{
array_walk_recursive($_POST, $strip);
}
if (isset($_REQUEST))
{
array_walk_recursive($_REQUEST, $strip);
}
if (isset($_COOKIE))
{
array_walk_recursive($_COOKIE, $strip);
}
}
}
?>
<?php
class AutoCompletion
{public $Artiste;public $Description;public $Site_infos;}
//Initialisation de la liste
$list = array();
//Connexion MySQL
require('configuration.php'); // $db dans le fichier !
try {$db;}
catch (Exception $ex)
{echo $ex->getMessage();}
//Construction de la requete
$strQuery = "SELECT artiste Artiste, description Description, site_infos Site_infos FROM favoris WHERE ";
if (isset($_POST["artiste"]))
{$strQuery .= "artiste LIKE :artiste ";}
else { $strQuery .= "description LIKE :description ";
$strQuery .= "site_infos LIKE :site_infos ";
}
if (isset($_POST["maxRows"])) //Limite
{ $strQuery .= "LIMIT 0, :maxRows"; }
$query = $db->prepare($strQuery);
if (isset($_POST["artiste"]))
{ $value = "%".$_POST["artiste"]."%";
$query->bindParam(":artiste", $value, PDO::PARAM_STR);
}
else
{
$value = $_POST["description"]."%";
$query->bindParam(":description", $value, PDO::PARAM_STR);
$value = $_POST["site_infos"]."%";
$query->bindParam(":site_infos", $value, PDO::PARAM_STR);
}
if (isset($_POST["maxRows"])) //Limite
{ $valueRows = intval($_POST["maxRows"]);
$query->bindParam(":maxRows", $valueRows, PDO::PARAM_INT);
}
$query->execute();
$list = $query->fetchAll(PDO::FETCH_CLASS, "AutoCompletion");
echo json_encode($list);
?> |