致命错误:在非对象上调用成员函数fetch()?

时间:2012-05-04 20:20:55

标签: php mysql stored-procedures pdo

我收到了回复给我的信息

致命错误:运行以下内容时,在非对象上调用成员函数fetch()。但是,这似乎是零星的,有什么想法吗?

    $cc_transaction_conn = new PDO('mysql:host='.$server.';dbname='.$db2use, $dbuser, $dbpass);
    $cc_transaction_query = $cc_transaction_conn->query("CALLgenInsCCTransactionLog('".$vmcnum."',
                                                                                     ".$_SESSION[val].",
                                                                                    'Enrollment',
                                                                                    'Processor',
                                                                                    'Merchant',
                                                                                    'Auth',
                                                                                    '".$card_expiration_month."',
                                                                                    '".$card_expiration_year."',
                                                                                    ".$_SESSION[enrollment_fee].",
                                                                                    '".strtoupper($_SESSION[forename])."',
                                                                                    '".strtoupper($_SESSION[surname])."',
                                                                                    '".strtoupper($_SESSION[house_number])."',
                                                                                    '".strtoupper($_SESSION[street])."',
                                                                                    '".strtoupper($_SESSION[flat_number])."',
                                                                                    '".strtoupper($_SESSION[town])."',
                                                                                    '".strtoupper($billing_post_code)."',
                                                                                    '".$ip_address."',
                                                                                    @cc_insert_id)");
        $cc_transaction_result = $cc_transaction_query->fetch();
        $cc_insert_id = $cc_transaction_result['cc_insert_id'];
        $_SESSION[cc_insert_id] = $cc_insert_id;
        $cc_transaction_conn = NULL;

这是存储过程:

    CREATE DEFINER=`reliantuksite`@`%` PROCEDURE `genInsCCTransactionLog`(
                        vmc VARCHAR(16),
                        application_id INT UNSIGNED,
                        reas_description VARCHAR(50),
                        in_processor_name VARCHAR(50),
                        merc_name VARCHAR(50),
                        trans_type_description VARCHAR(50),
                        card_expiration_month VARCHAR(2),
                        card_expiration_year VARCHAR(4),
                        amount DECIMAL(6,2),
                        forename VARCHAR(50),
                        surname VARCHAR(50),
                        house_number VARCHAR(255),
                        street VARCHAR(255),
                        flat_number VARCHAR(75),
                        town VARCHAR(50),
                        postal_code VARCHAR(10),
                        ip_address VARCHAR(32),
                        OUT cc_insert_id INT)
    BEGIN

    DECLARE proc_id TINYINT;
    DECLARE pay_reason_id TINYINT;
    DECLARE merc_account_id INT;
    DECLARE trans_type_id TINYINT;
    SELECT processor_id INTO proc_id FROM cc_processor WHERE processor_name = in_processor_name;
    SELECT payment_reason_id INTO pay_reason_id FROM payment_reason WHERE reason_description = reas_description;
    SELECT merchant_account_id INTO merc_account_id FROM cc_merchant_account WHERE merchant_name = merc_name;
    SELECT transaction_type_id INTO trans_type_id FROM transaction_type WHERE transaction_type_description = trans_type_description;
    INSERT INTO
        cc_transaction_log 
            (transaction_sent_date,
            vmc_number,
            application_id,
            processor_id,
            payment_reason_id,
            merchant_account_id,
            transaction_type_id,
            card_expiration_month,
            card_expiration_year,
            amount,
            billing_forename,
            billing_surname,
            billing_house_number,
            billing_street,
            billing_flat_number,
            billing_town,
            billing_postal_code,
            host_ip)
    VALUES
        (NOW(),
        vmc,
        application_id,
        proc_id,
        pay_reason_id,
        merc_account_id,
        trans_type_id,
        card_expiration_month,
        card_expiration_year,
        amount,
        forename,
        surname,
        house_number,
        street,
        flat_number,
        town,
        postal_code,
        ip_address);
    SELECT LAST_INSERT_ID() INTO cc_insert_id;
    SELECT cc_insert_id;
END;;

1 个答案:

答案 0 :(得分:4)

如手册中所述,

PDO::query()可以在查询失败时返回PDOStatment个对象或FALSE。如果您尝试在非对象上调用methot - FALSE,那么它将无法生成您正在获取的错误消息。

因此,请检查query()结果是否为false,然后在其上调用fetch()