-1

我在数组中有以下数据,我想将每个数组索引的内容存储到 mysql 表 myforum 中:

    Array ( 
            [0] => zero, those players that are trialing for hib team, (hpb's) most of them are like 300 -400 pingers? umm..mager lagg and even worse when they play on uk server's i bet/ 
            [1] => 1998-04-25T213200Z 
            [2] => http//boards.ie/vbulletin/showpost.php?p=67075 
          ) 

mysql表列是:内容,日期,帖子

[0] index value should store in content column,
[1] should store in date column and
[2] should store in post column
4

2 回答 2

1

除了转义您留下的值外,我在您的代码中没有发现任何错误,这可能是由于您无法将数据插入表中。你可以试试下面的代码。

$con = mysql_connect("localhost","sufi","1234"); 
 if (!$con) 
     { 
     die('Could not connect: ' . mysql_error()); 

     } 
 mysql_select_db("test", $con); 
 $xml = simplexml_load_file("boards.xml"); 
 $products[0] = (string)current($xml->xpath("/sioctBoardPost/sioccontent")); 
 $products[1] = (string)current($xml->xpath("/sioctBoardPost/dctermscreated")); 
 extract($products); 
 mysql_query("INSERT INTO forum (txt_content,txt_date,txt_about) 
 VALUES ('".mysql_escape_string($products[0])."','".mysql_escape_string($products[1])."','".mysql_escape_string($products[2])."')"); ?> 
于 2013-01-17T10:29:13.257 回答
0

试试下面的例子:

<?php
$input_array = array('zero, those players that are trialing for hib team, (hpb\'s) most of them are like 300 -400 pingers? umm..mager lagg and even worse when they play on uk server\'s i bet','1998-04-25T213200Z','http//boards.ie/vbulletin/showpost.php?p=67075');
$input_array_count= count($input_array);
$coumn_array = array('content','date','post');
$input_array_implode="'".implode("','",$input_array)."'";
$coumn_array_implode="'".implode("','",$coumn_array)."'";
$insert_query=mysql_query("insert into tablename (".$coumn_array_implode.") values (".$input_array_implode.")") or die(mysql_error());
?>

我认为这可以帮助您解决问题。

于 2013-01-17T10:22:19.670 回答