mysql转mysqli或pdo
最近在测试一个开源的帮助文档 wiki web help 问题不断,mysql错误提示要求将MySQL链接改为mysqli 或者pdo,按照网上的资料操作几次都失败,想着我大segmentfault高手如云,求帮忙解决
代码如下:
<?php
$_CONFIG = true;
# obvious db stuff
$CFG_USER = 'root';
$CFG_PASSWORD = '123456';
$CFG_SERVER = 'localhost';
$CFG_DATABASE = 'db';
# this is the return address for emails
$CFG_RETURN_ADDRESS = '';
# for email subject
$CFG_SITE_NAME = '';
# this if true requires registration before edit
$CFG_REGISTERED_ONLY = FALSE;
$con = mysql_connect($CFG_SERVER,$CFG_USER,$CFG_PASSWORD);
mysql_select_db($CFG_DATABASE, $con);
mysql_set_charset('utf8',$con);
//This stops SQL Injection in POST vars
foreach ($_POST as $key => $value) {
$_POST[$key] = mysql_real_escape_string(str_replace("\\","\\\\",$value));
}
//This stops SQL Injection in GET vars
foreach ($_GET as $key => $value) {
$_GET[$key] = mysql_real_escape_string(htmlspecialchars ($value,ENT_QUOTES,'UTF-8'));
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$coon=mysqli_connct($host,$useranme,$password,$db);
mysqli_query($conn,"set names utf8");
foreach ($_POST as $key => $value) {
$_POST[$key] = mysqli_real_escape_string($conn,str_replace("\","\\",$value));
}
foreach ($_GET as $key => $value) {
$_GET[$key] = mysqli_real_escape_string($conn,htmlspecialchars ($value,ENT_QUOTES,'UTF-8'));
}
下面的同上
建议直接pdo