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.

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

报告相同问题?

悬赏问题

  • ¥20 求计算赫斯特(Hurst)指数
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大