douhan5853 2018-05-14 22:41
浏览 29
已采纳

从PHP 5.3应用程序调用mysql存储函数

I'm having issues calling a stored function in MYSQL DB from a PHP -v5.3.29 application.Below is my Stored procedure in MySql

It outputs a total number of working days between two given days

Code(in PHP) to call this stored function is written below:

$db = dbLink();
$result = $db->query("SELECT WORKDAYS('2018-04-01','2018-04-08')");
if (!$result) {
   die('Could not query:' . mysql_error());
}
echo '<script>';
 echo 'console.log('. json_encode( $result ) .')';
echo '</script>'

Problem is when I try to call this stored function from a PHP application I get returned an object with Null attributes.

I'm writing the output '$result' on web console and the screenshots are attached below. $result object on web console

  • 写回答

1条回答 默认 最新

  • dongmaijie5200 2018-05-14 23:16
    关注

    Your problem is that $result is just the result set. You need to actually fetch the data from the result set. If you're using mysqli, use

    $row = $result->fetch_array();
    $workdays = $row[0];
    

    if you're using PDO, you can get the result directly using

    $workdays = $result->fetchColumn();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据