Darkman75ful Darkman75ful - 1 year ago 83
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
Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download