作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我以这种方式使用 mysqli_real_escape 将值插入表中:
$noun = mysqli_real_escape_string($con,$noun);
$adjective = mysqli_real_escape_string($con,$adjective );
//$update1 = "UPDATE review_words SET adjective = CONCAT(adjective, ',', '$adjective'), noun = CONCAT(noun, ',', '$noun') ";
$update1 = "UPDATE review_words SET adjective = CONCAT(IFNULL(adjective, ''), ',', '$adjective'), noun = CONCAT(IFNULL(noun, ''), ',', '$noun') "; if (!mysqli_query($con,$update1))
{
// die('Error: ' . mysqli_error($con));
// echo "error";
}
我在这里没有收到错误。但是当我从中选择数据进行处理时,会出现错误:
restaurant : 16 Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where word = 'restaurant'' at line 1
这是我收到错误的地方:
$select1 = mysqli_query($con,"SELECT * from review_words");
while ($row = @mysqli_fetch_array($select1))
{
$noun = $row['noun'];
echo "Nons are : $noun <br><br>";
$adjective = $row['adjective'];
echo "Nons are : $adjective <br>";
}
我已经使用了mysql_real_escape,即使这样也显示出这种错误。我还需要使用其他东西吗?
完整代码如下:
foreach($response->businesses as $business)
{
echo "<img border=0 src='".$business->image_url."'><br/>";
echo "Local provider : ".$business->name."<br/>";
$rtext = $business->snippet_text;
echo "Review : ".$business->snippet_text."<br/>";
if( $item = 'Italian_restaurants' or $item = 'Mexican_restaurants')
{
$keywords = MakeExternalReq($business->snippet_text);
echo "<strong>Important keyword : </strong>".$keywords."<br/>";
$tagger = new PosTagger('lexicon.txt');
$tags = $tagger->tag($rtext);
$noun = printTagN($tags);
$adjective = printTagA($tags);
$noun = implode(", ",$noun);
$adjective = implode(", ",$adjective);
echo "Noun : $noun <br>";
echo "Adjectives : $adjective <br>";
//var_dump($var);
}
echo "Rate : ".$business->rating."<br/>";
echo "Phone : ".$business->phone."<br/>";
echo "Address : ".$business->location->display_address[0]."<br/>";
echo "Category : ".$business->categories[0][0];
echo "<hr>";
$brand = 'Yelp';
$local_provider = $business->name;
$review = $business->snippet_text;
$id = md5($review);
$rate = $business->rating;
$image = $business->image_url;
$phone = $business->phone;
$address = $business->location->display_address[0];
$category = $business->categories[0][0];
$con = mysqli_connect('127.0.0.1', 'root', 'root', 'root');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$insertQuery1 = "INSERT INTO review_details(`id`,`brand`,`local_provider`,`review`,`rate`,`important_words`,`adjective`,`noun`,`image`,`phone`,`address`,`category`) VALUES ('".$id."','".$brand."','".$local_provider."','".$text."','".$rate."','".$keywords."','".$adjective."','".$noun."','".$image."','".$phone."','".$address."','".$category."')";
if (!mysqli_query($con,$insertQuery1))
{
// die('Error: ' . mysqli_error($con));
// echo "error";
}
$noun = mysqli_real_escape_string($con,$noun);
$adjective = mysqli_real_escape_string($con,$adjective );
//$update1 = "UPDATE review_words SET adjective = CONCAT(adjective, ',', '$adjective'), noun = CONCAT(noun, ',', '$noun') ";
$update1 = "UPDATE review_words SET adjective = CONCAT(IFNULL(adjective, ''), ',', '$adjective'), noun = CONCAT(IFNULL(noun, ''), ',', '$noun') "; if (!mysqli_query($con,$update1))
{
// die('Error: ' . mysqli_error($con));
// echo "error";
}
}
}
function get_word_count()
{
echo "<br> Entered into word count <br>";
$con = mysqli_connect('127.0.0.1', 'root', 'root', 'root');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$select1 = mysqli_query($con,"SELECT * from review_words");
while ($row = @mysqli_fetch_array($select1))
{
$noun = $row['noun'];
echo "Nons are : $noun <br><br>";
$adjective = $row['adjective'];
echo "Nons are : $adjective <br>";
}
$noun_count = array_count_values(str_word_count($noun, 1));
$adjective_count = array_count_values(str_word_count($adjective, 1));
//echo $noun_count;
arsort($noun_count);
//print_r($noun_count);
arsort($adjective_count);
//print_r($adjective_count);
//echo $noun_count;
foreach($noun_count as $key=>$value)
{
echo "$key : $value ";
$insertQuery2 = "INSERT INTO review_word_count (`word`,`count`,`type`) VALUES ('".$key."','".$value."','noun') ON DUPLICATE KEY UPDATE count = '".$value."' where word = '".$key."'";
if (!mysqli_query($con,$insertQuery2))
{
die('Error: ' . mysqli_error($con));
// echo "error";
}
}
foreach($adjective_count as $key=>$value)
{
$insertQuery3 = "INSERT INTO review_word_count (`word`,`count`,`type`) VALUES ('".$key."','".$value."','adjective') ON DUPLICATE KEY UPDATE count = '".$value."' where word = '".$key."'";
if (!mysqli_query($con,$insertQuery3))
{
die('Error: ' . mysqli_error($con));
// echo "error";
}
}
echo "<br> End into word count <br>";
}
最佳答案
删除这个
where word = '".$key."'
来自您的插入查询。
插入该键时,不必在此处创建 where 子句,因此查询将自动查找该插入的键。
还有
echo "$key : $value ";
应该是
echo $key. " : ".$value ;
关于php - 插入值时 mysqli_real_escape 看起来不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23042451/
我一直在将我的站点从 mysql 转换为 mysqli,我想知道如何像 mysqli_real_escape_string 一样使用 mysqli_real_escape_string。换句话说,我如
我以这种方式使用 mysqli_real_escape 将值插入表中: $noun = mysqli_real_escape_string($con,$noun); $adjectiv
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: mysql_escape_string VS mysql_real_escape_string 我需要将 co
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: mysql_escape_string VS mysql_real_escape_string 我需要将 co
我是一名优秀的程序员,十分优秀!