douer9399 2014-07-16 13:28
浏览 30

在前7次运行后,php函数无法正常工作

hi i have a function that gets Data from an ODBC connection

public function SageData() {
    $this->Arr = array();
    $conn = odbc_connect('Data hub', '', '');
    if (!$conn) {
        exit("Connection Failed: " . $conn);
    }
    $sql = "SELECT [SHOP FLOOR PRODUCTION PLAN].[MACHINE], [SHOP FLOOR PRODUCTION PLAN].[cycletime]
    FROM [SHOP FLOOR PRODUCTION PLAN]
     WHERE ((([SHOP FLOOR PRODUCTION PLAN].[MACHINE])='$this->name'));

";

    $rs = odbc_exec($conn, $sql);
    if (!$rs) {
        exit("Error in SQL");
    }

    while (odbc_fetch_row($rs)) {

        $this->Cycletime = odbc_result($rs, "cycletime");
    }

    odbc_close($conn);
    return round($this->Cycletime, 2);
}

This function is part of a class below is the code to create a new object in the class, In the function the $this->name corresponds to the ZW01001 and so on numbers

Machinecycle("ZW01001", "ZW01001Percent", 0);
Machinecycle("ZW01004", "ZW01004Percent", 1);
Machinecycle("ZW01005", "ZW01005Percent", 2);

the function is called by another function in the class to turn the data in to a percentage i can use see below

public function GetM() {

    $q = $this->Cycle();
    $qq = $this->SageData();

    $this->M = $q - $qq;
  //  $this->P = $this->M / $this->sageData();

    if ($qq == 0) {
        $this->P = 0;
    } else {
        $this->P = $this->M / $this->sageData();
    }

    return round($this->P, 2);
}

The Values outputted by GetM are put in to an array, my problem is that when i run this i get the data for the first 7 out of 14 objects and this error for the rest of them

Notice: Undefined property: machine::$Cycletime in C:\Somepath\Datatest.php on line 104

Line 104 is this part

    return round($this->Cycletime, 2);

What i do not understand is why it is doing this after the first 7 and failing on the rest the data is there

  • 写回答

1条回答 默认 最新

  • dongqian1028 2014-07-16 13:34
    关注

    Well let's first state the obvious, in this bit

    return round($this->Cycletime, 2);
    

    $this->Cycletime seems to be undefined at the point where it spams the errors.

    Next i see that this Cycletime is received from your odbc connection.

    $this->Cycletime = odbc_result($rs, "cycletime");
    

    Have you in fact checked that it is set all the time? because it looks like the query simply isn't returning data. So in order to fix it, make sure that your query does what it is supposed to and delivers the Cycletime.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题