drbvm26000 2016-11-18 23:45
浏览 35
已采纳

试图从MySQL访问PHP中的存储过程

So I created a stored procedure in phpMyAdmin named Ratio_Viewer. It takes in one parameter which is a stock ticker. I tested it in phpMyAdmin and I received the correct tuples. Now I am trying to incorporate that into my php files. I have a page where you enter a ticker and it takes you to another page which is supposed to display you the data based upon the stock ticker you entered. Nothing is getting returned. My code is:

require 'connection.php';
$sql = "CALL Ratio_Viewer('" . $_REQUEST["ticker"] . "')";

if(!$result = $mysqli->query($sql)) {
  echo "error: " . $mysqli->error . "<br>";
  exit;
}

echo ($result->fetch_assoc());
  • 写回答

1条回答 默认 最新

  • dpo60833 2016-11-19 00:01
    关注

    Your code is working.

    echo ($result->fetch_assoc());
    

    will simply print "Array". PHP does not print arrays in a readable format in this case.

    You can use print_r or var_dump or implement a loop to print the data you want. For example,

    foreach ($result->fetch_assoc() as $k => $v) echo "$k is $v <br>";
    

    Your code is vulnerable to SQL injection.

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

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器