简单执行插入


Simple Exec Insert

问题是我认为我做错了什么,我只是不知道是什么。我试过try/catch,这段代码的其他部分都正常运行(我已经响应了所有内容),但没有任何内容被插入"文本"。我99%肯定它不是特权,也作为一个一般的问题是可以使用执行时,你只是拍摄周围的数据在你的服务器和从其他url ?希望能得到一些回复。

<?php
include('simplehtmldom_1_5/simple_html_dom.php');  
$html = new simple_html_dom();  
$html->load_file('http://www.youtube.com/live/all/videos?sort=dd&tag_id=&view=41');
$count = 0;
$pdo = new PDO('mysql:host=localhost;dbname=scraper', 'user', 'aa');
$string = $pdo->query('SELECT text FROM urls');
while ($row = $string->fetch())
{
  $links[] = $row['text'];
}
foreach($html->find('[class=content-item-title yt-ui-ellipsis yt-ui-ellipsis-2]') as $element)
{
$array[$count]=$element->href;
foreach ($links as $link)
{
if (strpos($array[$count], $link) == false)
{
$pdo->exec('INSERT INTO urls SET
text=$array[$count]');
}
}
$count += 1;
}
?>

代替

$pdo->exec('INSERT INTO urls SET text=$array[$count]');

使用这个

$pdo->prepare('INSERT INTO urls SET text=?')->execute(array($array[$count]));

花时间阅读关于PDO的准备。还有关于变量解析