douxing9567 2016-06-07 10:02
浏览 112
已采纳

mysql_query无法在最新的php版本中运行

I am trying to insert data in to MySQL Database, but have been stuck on Data insertion.

I am using Version 3.0.0 of WampServer and PHP 5.6.16, phpMyAdmin 4.5.2.

Everything else are ok, I can UPDATE, DELETE...Except INSERT INTO.

Code

<?php 
$con=@mysql_connect('localhost','root','');
mysql_query('SET NAMES utf8;');
mysql_select_db('mydb',$con);
////////////////////////////////// 
if(isset($_POST['post_files'])) {  
$files = $_POST['files']; 
$title = $_POST['title']; 
////////////////////////////////// 
$query = "INSERT INTO files (`file`, `title`) VALUES ('$files', '$title')";  
if(mysql_query($query))
{ 
echo'OK, Data Inserted.'; 
}
else
{ 
echo 'Sorry! Operation failed.';
}  
}
mysql_close(); 
?>
        

These Bunch of codes were working fine in previous PHP versions.

</div>
  • 写回答

1条回答 默认 最新

  • dongyan5706 2016-06-07 10:25
    关注

    instead of mysql use mysqli For instance:

    • mysql_connect will be replaced by mysqli_connect
    • mysql_query will be replaced by mysqli_query($con, $query)
    • and so on

    Note that, for some functions, you may need to check the parameters carefully: Maybe there are some differences here and there -- but not that many, I'd say: both mysql and mysqli are based on the same library (libmysql ; at least for PHP <= 5.2)

    For instance :

    with mysql, you have to use the mysql_select_db once connected, to indicate on which database you want to do your queries mysqli, on the other side, allows you to specify that database name as the fourth parameter to mysqli_connect. Still, there is also a mysqli_select_db function that you can use, if you prefer.

    For more information read this article : PHP MySQL to MySQLi

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了