调用未定义的方法PDO::execute(),先前的答案不能解决错误


Call to undefined method PDO::execute(), previous answers doesn't solve the error

我试图通过php使CSV导入函数,该函数将信息存储在MySQL数据库中,但由于某种原因,它给出了以下错误:-

致命错误:调用未定义方法PDO::execute()在/home/a/public_html/admin/admin_import_product.php第25行

<?php  
session_start();
include '../inc/inc.functions.php';
include '../dbconnector.php';
include '../dbpdo.php';
include '../inc/inc.config.php';
if((isset($_SESSION['admin'])) && ($_SESSION['admin'] == 1))
{
    $adminusername = $_SESSION['username'];
    $date=date('Y-m-d');
    if ($_FILES[csv][size] > 0) { 
        //get the csv file 
        $file = $_FILES[csv][tmp_name]; 
        $handle = fopen($file,"r"); 
         //prepare the statement for the insertion of the record via PDO
        try{
            global $conn;
            $statement = $conn->prepare("INSERT INTO products(category,productname,baseprice,basepricewd,basepricenw,addedby,addedon) VALUES (?,?,?,?,?,?,?)");
            //loop through the csv file and insert into database 
            do { 
                if ($data[0]) { 
                    $statement=$conn->execute(array(
                        $data[0],
                        $data[1],
                        $data[2],
                        $data[3],
                        $data[4],
                        $adminusername,
                        $date));
                } 
            } while ($data = fgetcsv($handle,5000,",","'")); 
        // 
    }//try
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }

        //redirect 
       // header('Location: admin_importproducts_home.php?success=1'); die; 
        echo "Products imported successfully";
    } 
 }
   else
{
    header('Location:http://a.co.uk/' . $config["admindir"] . '/adminlogin');
}
?>

您正在从错误的对象/资源(无论PDO是什么)调用execute():

// this is the proper chain of calls as stated in the documentation
$statement = $conn->prepare();
$execute_result = $statement->execute();
// execute() returns a boolean so you can use an if/else block to know if your query is hunky-dory
if($execute_result)
{
    // yay the query had no errors!
}
else
{
    // aww snap, you messed up now!
}
http://www.php.net/manual/en/pdostatement.execute.php