2

我收到以下消息返回给我

致命错误:运行以下命令时调用非对象上的成员函数 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;;
4

1 回答 1

4

PDO::query(),如手册中所写,可以返回一个PDOStatment对象,或者FALSE如果查询失败。如果您尝试在非对象 - 上调用方法,当然FALSE它将无法生成您收到的错误消息。

所以,检查query()结果是否为假,然后调用fetch()它。

于 2012-05-04T20:31:36.890 回答