将变量数组插入mysql数据库

时间:2013-04-19 07:42:49

标签: php mysql web-scraping

所以...我有这个回声声明:

echo 
$results['results'][0]['url'].','
.$results['results'][1]['url'].','
.$results['results'][2]['url'].','
.$results['results'][3]['url'].','
.$results['results'][4]['url'].','
.$results['results'][5]['url'].','
.$results['results'][6]['url'].','
.$results['results'][7]['url'].','
.$results['results'][8]['url'].','
.$results['results'][9]['url'].','

.$results['results'][0]['title'].','
.$results['results'][1]['title'].','
.$results['results'][2]['title'].','
.$results['results'][3]['title'].','
.$results['results'][4]['title'].','
.$results['results'][5]['title'].','
.$results['results'][7]['title'].','
.$results['results'][8]['title'].','
.$results['results'][9]['title'].','

.$results['results'][0]['desc'].','
.$results['results'][1]['desc'].','
.$results['results'][2]['desc'].','
.$results['results'][3]['desc'].','
.$results['results'][4]['desc'].','
.$results['results'][5]['desc'].','
.$results['results'][6]['desc'].','
.$results['results'][7]['desc'].','
.$results['results'][8]['desc'].','
.$results['results'][9]['desc'];

这是有效的,并输出前10个网址,前10个标题,以及我所拥有的google刮刀中的前10个描述(我告诉你这个以证明脚本有效)(有很多文件)显示,所以我不会在这里展示他们)。我想将数据输入到mysql数据库中。

这个回声,回声这样的值:对于某个关键词......

    http://cars.mainetoday.com/,http://www.nowvauxhall.co.uk/,http://www.youtube.com/watch?v=nDvggf0ltVo,......

就像你可以看到的那样,它们都用逗号分隔,并准备输入到mysql数据库中。 数据库的连接和选择由一个工作(或我认为)的小脚本处理。 (再一次,我不打算显示文件,因为它们都是连接的,它们大约是5或6个而且它们很长),所以...... 这是我用来在表中添加一行的输入代码:

mysql_query(

"INSERT INTO  'seo'.'serp' (
`keyword` ,
`URL1` ,
`URL2` ,
`URL3` ,
`URL4` ,
`URL5` ,
`URL6` ,
`URL7` ,
`URL8` ,
`URL9` ,
`URL10` ,
`Title1` ,
`Title2` ,
`Title3` ,
`Title4` ,
`Title5` ,
`Title6` ,
`Title7` ,
`Title8` ,
`Title9` ,
`Title10` ,
`Description1` ,
`Description2` ,
`Description3` ,
`Description4` ,
`Description5` ,
`Description6` ,
`Description7` ,
`Description8` ,
`Description9` ,
`Description10`
)
VALUES (
'cars to sale',


".htmlentities($results['results'][0]['url']).",
".htmlentities($results['results'][1]['url']).",
".htmlentities($results['results'][2]['url']).",
".htmlentities($results['results'][3]['url']).",
".htmlentities($results['results'][4]['url']).",
".htmlentities($results['results'][5]['url']).",
".htmlentities($results['results'][6]['url']).",
".htmlentities($results['results'][7]['url']).",
".htmlentities($results['results'][8]['url']).",
".htmlentities($results['results'][9]['url']).",

".htmlentities($results['results'][0]['title']).",
".htmlentities($results['results'][1]['title']).",
".htmlentities($results['results'][2]['title']).",
".htmlentities($results['results'][3]['title']).",
".htmlentities($results['results'][4]['title']).",
".htmlentities($results['results'][5]['title']).",
".htmlentities($results['results'][6]['title']).",
".htmlentities($results['results'][7]['title']).",
".htmlentities($results['results'][8]['title']).",
".htmlentities($results['results'][9]['title']).",

".htmlentities($results['results'][0]['desc']).",
".htmlentities($results['results'][1]['desc']).",
".htmlentities($results['results'][2]['desc']).",
".htmlentities($results['results'][3]['desc']).",
".htmlentities($results['results'][4]['desc']).",
".htmlentities($results['results'][5]['desc']).",
".htmlentities($results['results'][6]['desc']).",
".htmlentities($results['results'][7]['desc']).",
".htmlentities($results['results'][8]['desc']).",
".htmlentities($results['results'][9]['desc']));

输入行似乎不喜欢表...;)我也尝试过:

mysql_query(

"INSERT INTO  'seo'.'serp' (
`keyword` ,
`URL1` ,
`URL2` ,
`URL3` ,
`URL4` ,
`URL5` ,
`URL6` ,
`URL7` ,
`URL8` ,
`URL9` ,
`URL10` ,
`Title1` ,
`Title2` ,
`Title3` ,
`Title4` ,
`Title5` ,
`Title6` ,
`Title7` ,
`Title8` ,
`Title9` ,
`Title10` ,
`Description1` ,
`Description2` ,
`Description3` ,
`Description4` ,
`Description5` ,
`Description6` ,
`Description7` ,
`Description8` ,
`Description9` ,
`Description10`
)
VALUES (
'cars to sale',


".$results['results'][0]['url'].",
".$results['results'][1]['url'].",
".$results['results'][2]['url'].",
".$results['results'][3]['url'].",
".$results['results'][4]['url'].",
".$results['results'][5]['url'].",
".$results['results'][6]['url'].",
".$results['results'][7]['url'].",
".$results['results'][8]['url'].",
".$results['results'][9]['url'].",

".$results['results'][0]['title'].",
".$results['results'][1]['title'].",
".$results['results'][2]['title'].",
".$results['results'][3]['title'].",
".$results['results'][4]['title'].",
".$results['results'][5]['title'].",
".$results['results'][6]['title'].",
".$results['results'][7]['title'].",
".$results['results'][8]['title'].",
".$results['results'][9]['title'].",

".$results['results'][0]['desc'].",
".$results['results'][1]['desc'].",
".$results['results'][2]['desc'].",
".$results['results'][3]['desc'].",
".$results['results'][4]['desc'].",
".$results['results'][5]['desc'].",
".$results['results'][6]['desc'].",
".$results['results'][7]['desc'].",
".$results['results'][8]['desc'].",
".$results['results'][9]['desc']);

仍然没有结果......但没有错误! ??? 如果回声有效,为什么我不能插入行???为什么它没有显示任何错误? 我已经在这工作了大约15个小时!我相信这很简单......

我还尝试过foreach循环,其中2个循环,每个变量子集一个循环。没有错误,但没有插入行。

有人可以帮忙吗? 谢谢, 米格尔

喜欢这个吗?

mysql_query(

"INSERT INTO  'seo'.'serp' (
`keyword` ,
`URL1` ,
`URL2` ,
`URL3` ,
`URL4` ,
`URL5` ,
`URL6` ,
`URL7` ,
`URL8` ,
`URL9` ,
`URL10` ,
`Title1` ,
`Title2` ,
`Title3` ,
`Title4` ,
`Title5` ,
`Title6` ,
`Title7` ,
`Title8` ,
`Title9` ,
`Title10` ,
`Description1` ,
`Description2` ,
`Description3` ,
`Description4` ,
`Description5` ,
`Description6` ,
`Description7` ,
`Description8` ,
`Description9` ,
`Description10`
)
VALUES (
'cars to sale',



'".htmlentities($results['results'][0]['url'])."',
'".htmlentities($results['results'][1]['url'])."',
'".htmlentities($results['results'][2]['url'])."',
'".htmlentities($results['results'][3]['url'])."',
'".htmlentities($results['results'][4]['url'])."',
'".htmlentities($results['results'][5]['url'])."',
'".htmlentities($results['results'][6]['url'])."',
'".htmlentities($results['results'][7]['url'])."',
'".htmlentities($results['results'][8]['url'])."',
'".htmlentities($results['results'][9]['url'])."',

'".htmlentities($results['results'][0]['title'])."',
'".htmlentities($results['results'][1]['title'])."',
'".htmlentities($results['results'][2]['title'])."',
'".htmlentities($results['results'][3]['title'])."',
'".htmlentities($results['results'][4]['title'])."',
'".htmlentities($results['results'][5]['title'])."',
'".htmlentities($results['results'][6]['title'])."',
'".htmlentities($results['results'][7]['title'])."',
'".htmlentities($results['results'][8]['title'])."',
'".htmlentities($results['results'][9]['title'])."',

'".htmlentities($results['results'][0]['desc'])."',
'".htmlentities($results['results'][1]['desc'])."',
'".htmlentities($results['results'][2]['desc'])."',
'".htmlentities($results['results'][3]['desc'])."',
'".htmlentities($results['results'][4]['desc'])."',
'".htmlentities($results['results'][5]['desc'])."',
'".htmlentities($results['results'][6]['desc'])."',
'".htmlentities($results['results'][7]['desc'])."',
'".htmlentities($results['results'][8]['desc'])."',
'".htmlentities($results['results'][9]['desc'])."')")

不工作,没有错误......

Ther是连接文件:

<?php

$conn_error = 'Could not connect.';

$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';

$mysql_db = 'seo';

if (!mysql_connect($mysql_host, $mysql_user, $mysql_pass)||!mysql_select_db($mysql_db)) {

die($conn_error);
}
echo 'connected';
?>

就像你在页面顶部的回声中看到的那样,它在结尾处给出了“连接”......

还有其他什么?

1 个答案:

答案 0 :(得分:0)

您必须将文本数据包含在此{/ 1}}

'

其他人