duangu9997 2016-05-20 10:21
浏览 21
已采纳

当错误[重复]时,mysql是否将数据返回到php变量

This question already has an answer here:

so i created php variable contain mysql query inside , but is it will return data to the php variable when the table / column / data is not available ?

example :

 $a1='1';
$item1nanowr = mysql_query("SELECT item_name FROM item_info WHERE item_special_number = $a1 ");

now just imagine that item_name column not available , is it will return data ?

and if i put "or die" statement like this :

$item1nanowr = mysql_query("SELECT item_name FROM item_info WHERE item_special_number = $a1 ") or die("Coming Soon");

is it will return word Coming Soon ?

</div>
  • 写回答

1条回答 默认 最新

  • doude4201 2016-05-20 10:33
    关注

    or die() will run only if something goes wrong with the query. Several things could go wrong. Some of them are:

    • The database table does not exist
    • One of the specified columns does not exist
    • There is a syntax error in the query
    • The database is offline or the connection has been lost

    So it will run on critical errors. It won't run if your table or a specific column is empty.

    Also it is very important to stop using mysql_ functions!. The mysql extension is deprecated from PHP 5.5 and completely removed from PHP 7.

    Use mysqli or PDO instead. You should also use Prepared Statements instead of directly interpolating variables in your query. More on Prepared Statements here

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

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划