我将表名作为 php 变量来将数据插入表中。 但它给出了错误。这里有什么不好?
if($flag == 1)
$table = 'frrole_pupolar_article';
else
$table = 'frrole_category_article';
$insertQuery1 = "INSERT INTO '.$table.' (`url`, `sentiment`, `category`, `title` ,`time`,`img_url`,`rt_count`,`tweet_count`) VALUES ('".$url."','".$setiment."','".$category."','".$title."','".$time."','".$img_url."','".$rt_count."','".$tweet_count."')";
错误:
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 ''.frrole_category_article.' (`url`, `sentiment`, `category`, `title` ,`time`,`im' at line 1
最佳答案
$insertQuery1 = "INSERT INTO '" .$table. "' (`url`, `sentiment`, `category`, `title` ,`time`,`img_url`,`rt_count`,`tweet_count`) VALUES ('".$url."','".$setiment."','".$category."','".$title."','".$time."','".$img_url."','".$rt_count."','".$tweet_count."')";
您错误地编写了 '.$table.'
而不是 '".$table."'
关于php - 将数据作为 php 变量插入到 table_name 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084639/