Darkman75ful Darkman75ful - 6 months ago 49
PHP Question

Sql request with php : select posts where there is a youtube link

I tried to make a sql request with php which selects posts where there is a youtube link but it doesn't works.

This is what I did :

$bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');
$sql = "SELECT * FROM posts WHERE post REGEXP :motif";
$params = array(':motif'=>$motif);
$search_for_yt_links = $bdd->prepare($sql);

$result = $search_for_yt_links->fetch();

I get this result :


This shuld be :

array (size=1)
'post' => string 'Look at my new video https://www.youtube.com/watch?v=y2Xef0CnUYA. Awesome ?' (length=75)

Unfortunately it doesn't work.
Can you help me ?


Max Max

This regex detects full links and short ones (youtu.be)