MySQL在继续使用SELECT语句之前完成CREATE OR REPLACE VIEW

时间:2015-08-13 18:30:16

标签: php mysql pdo

我有以下代码执行CREATE OR REPLACE语句,然后在这些视图上运行SELECT语句。不幸的是,SELECT语句回来说视图不存在。如何在选择之前运行视图并完成?

$dbh = self::sql_connect( $sql_details );
        $dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

        $CRV = "CREATE OR REPLACE VIEW ".$setdbaseBrand."storeCheckRecords_max as (
            SELECT MAX(datetimesql) as maxdatetimesql, upc, store_id
            FROM ".$setdbaseBrand."storeCheckRecords
            GROUP BY upc, store_id
            );

            CREATE OR REPLACE VIEW ".$setdbaseBrand."storeCheckRecords_ext as (
            SELECT store_id, $fields_create_view
            FROM ".$setdbaseBrand."storeCheckRecords_max
            );

            CREATE OR REPLACE VIEW ".$setdbaseBrand."storeCheckRecords_extended as (
            SELECT store_id, $fields_create_view_more
            FROM ".$setdbaseBrand."storeCheckRecords_ext
            GROUP BY store_id
            );";

        $sth = $dbh->prepare($CRV);
        $sth->execute();

    $data = self::sql_exec( $db, $bindings,"SELECT SQL_CALC_FOUND_ROWS @storeid:=z.id,z.biz_name, z.wf_store_name, z.e_address, z.e_city, z.e_state, z.e_postal, CASE WHEN total_sales IS NULL AND prev_total_sales IS NULL THEN 'CV' ELSE IFNULL(total_sales,0)-IFNULL(prev_total_sales,0) END as diff_total_sales, IFNULL(d_source,'N/A') as d_source, $fields_selectVoid FROM.........

0 个答案:

没有答案