-
-
Save uno-de-piera/c404c134f77b1e4b65f65341fadc04fe to your computer and use it in GitHub Desktop.
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
<?php | |
class Conectar | |
{ | |
public static function con() | |
{ | |
$conexion = mysql_connect("localhost","root",""); | |
mysql_query("SET NAMES 'UTF-8'"); | |
mysql_select_db("el_blog"); | |
return $conexion; | |
} | |
} | |
class Buscador | |
{ | |
private $busqueda=array(); | |
public function buscar() | |
{ | |
$busqueda = mysql_real_escape_string(addslashes($_GET['s'])); | |
/*consulta fulltext con el motor myisam | |
$query = "SELECT *, MATCH(titulo, cuerpo) AGAINST ('$busqueda') as buscado | |
FROM posts | |
WHERE MATCH(titulo, cuerpo) | |
AGAINST ('$busqueda') | |
ORDER BY buscado DESC"; | |
*/ | |
//consulta con like y el motor innodb | |
$query = "SELECT * FROM posts WHERE titulo like '%".$busqueda."%' OR cuerpo like '%".$busqueda."%';"; | |
$res = mysql_query($query,Conectar::con()); | |
while ($reg=mysql_fetch_assoc($res)) | |
{ | |
$this->busqueda[] = $reg; | |
} | |
return $this->busqueda; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment