douwen2158 2015-04-12 15:54
浏览 156
已采纳

调用未定义的函数fetch_row()

Im connecting to database:

$con=mysql_connect("localhost","root","");
mysql_set_charset('utf8',$con);
mysql_select_db("mydb");

And when I try to get a row using within a for each with this code:

$question = fetch_row("SELECT * FROM `mytable` WHERE PyetjaNr = $i ORDER BY RAND() LIMIT 1 "); 

Im getting this error:

Fatal error: Call to undefined function fetch_row() 

Same code is working in my hosting server (mysql 5.5), but not working in my localhost mysql (5.6),

Is problem to mysql version? can I do anything except upgrading to mysqli?

  • 写回答

1条回答 默认 最新

  • douhongxie5436 2015-04-12 16:54
    关注

    You may have missed this in the PHP manual (in which case, you should read the manual for functions you use), but the mysql_... functions are deprecated, and will almost certainly not even be in 5.7 when it comes out. They were replaced with the mysqli_... set of functions, so use those instead.

    The PHP manual for mysqli::set_charset covers the initial setup you need, and getting data out of your db is then simply a matter of querying it the normal way.

    Which usually means making use of prepared statements instead of just building your SQL as a string (because you want to be secure, you don't want to be Bobby Tables)

    Wipe what you have now, redo it with mysqli functions. If your problem still exists, at least now you'll have modern code that people can comment on for putting in your question.

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器