dongqiuxu2270
2014-05-23 10:11
浏览 590
已采纳

将LaTeX代码插入MySQL

I am using PHP and MySql. TeX is posted to server.php file through a form and exploded into an array:

foreach($_POST['ques'] as $i){  
  $arr = explode('~', $i);
}

$sql = "INSERT INTO `QUESTIONS`(`Text`) VALUES ('$arr[2]')";

$run = mysql_query( $sql, $conn ) or die(mysql_error());

Btw echo $arr[2]; shows correct Tex syntax : "[\Rightarrow{z=\frac{43}{-44}}]"

But on database it is stored without backslashes "[Rightarrow{z=frac{43}{-44}}]"

图片转代码服务由CSDN问答提供 功能建议

我正在使用PHP和MySql。 TeX通过表单发布到server.php文件并展开成一个数组:

  foreach($ _ POST ['ques'] as $ i){
 $ arr =  explode('〜',$ i); 
} 
 
 $ sql =“INSERT INTO`QUESTIONS`(`Text`)VALUES('$ arr [2]')”; 
 
 $ run =  mysql_query($ sql,$ conn)或die(mysql_error()); 
   
 
 

Btw echo $ arr [2]; 显示正确的Tex语法:“[\ Rightarrow {z = \ frac {43} { - 44}}]”

但在数据库中,它存储时没有反斜杠“[Rightarrow {z = frac {43} { - 44}}]“

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongren4099 2014-05-23 12:35
    已采纳

    Do not use old mysql_* functions. Use mysqli_*. or PDO as in this example.

    The parameterized/prepared query makes you to stop worrying about quoting and malicious sql-attacks. (But drive safely anyway)

    $dsn = 'mysql:dbname=testdb;host=127.0.0.1';
    $dbh = new PDO($dsn, $user, $password);
    $sth = $dbh->prepare("INSERT INTO `QUESTIONS`(`Text`) VALUES (?)");
    $sth->execute(array($arr[2]));
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题