PDO错误,无法从表中获取字段

时间:2019-03-09 11:56:15

标签: php pdo

当我尝试从字段g_code中获取记录时,它恢复了如下错误: 注意:尝试在第388行的/var/www/waletmas.local/sites/waletmas.php中获取非对象的属性

这些是我的代码:

include "class/_parkersales.php";
if (isset($_POST['save']))
{
    try
        {
            $pdo1 = new PDO('mysql:host=localhost;dbname=waletmas', 'root', 'root');

        }
        catch (PDOException $e)
        {
            echo 'Error: ' . $e->getMessage();
            exit();
         }

    foreach ($_SESSION["databind1"] as $item)
    {
        //echo $item["code"];
        //echo '<br/>';
        $invcode=$item["code"];
        $mcode=1;
        try {
            $pdo1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql1 = "SELECT * FROM wsellhead WHERE s_code='$invcode'" ;
            $stmt1 = $pdo1->prepare($sql1);
            $stmt1->bindParam(':c_code', $mcode, PDO::PARAM_STR);
            $stmt1->execute();
            $total1 = $stmt1->rowCount();
            /*while ($row = $stmt->fetchObject()) {
              echo $row->c_code;
            }*/
        } catch(PDOException $e) {
            echo $e->getMessage();
        }

        $row2 = $stmt1->fetchObject();


        //echo $row2->s_code.' '.$row2->s_date.' '.$row2->s_dateinput.' '.$row2->c_code.' '.$row2->u_code.' '.$row2->s_premi.' '.$row2->s_deduct;
        $myinvno=$row2->s_code;
        $mydateon=$row2->s_date;
        $mydate1=$row2->s_dateinput;
        $t_cust=$row2->c_code;
        $mypremi=$row2->s_premi;
        $mydeduct=$row2->s_deduct;


        $salesf = new Sales($row2->s_code,$row2->s_date,$row2->s_dateinput,$row2->c_code,$row2->u_code,$row2->s_premi,$row2->s_deduct,'0','0','0','0','0','0','0');
        //
        $salesf->save_sell_headf();



        try {
            //$pdo1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = "SELECT * FROM wselltailf WHERE s_code='$invcode'" ;
            $stmt = $pdo1->prepare($sql);
            $stmt->bindParam(':c_code', $mcode, PDO::PARAM_STR);
            $stmt->execute();
            $total = $stmt->rowCount();
            /*while ($row = $stmt->fetchObject()) {
              echo $row->c_code;
            }*/
        } catch(PDOException $e) {
            echo $e->getMessage();
        }

                $row3 = $stmt->fetchObject();

                echo $row3->g_code;

我的浏览器出现错误注意:试图在第388行的/var/www/waletmas.local/sites/waletmas.php中获取非对象的属性

谢谢

0 个答案:

没有答案