通过$ POST导入时,有没有办法处理来自MySQL的大型列

时间:2018-11-08 14:17:36

标签: php mysql

我正在尝试使用API​​将数据导入MySQL数据库。 我有小规模的工作。

我现在对其进行了更改,使其更符合当前数据库。它的表很大,结构也很差,但是为了简化和维护,我试图保持MySQL数据库和Applications数据库的内联。 MSQL =基于Windows的应用程序: MySQL =服务器数据库,正在从本地托管的MSQL中提取数据并将其导入到外部托管的MySQL数据库中。

随着我扩展代码,它不再起作用,这可能是许多因素,例如表需要结构化/索引/主要,或者我通过查询传递了太多数据。该应用程序开始看起来非常混乱。

问题是,是否有必要并且更好地实践一下我列出每一列并匹配试图使用MySQL INFORMATION_SCHEMA来列出列的数据集。

到目前为止,这是代码,我已经删除了许多列。

我们有一个服务器和主机:

服务器代码

类文件:Api.php

class API
{
    private $connect = '';

    function __construct()
    {
        $this->database_connection();
    }

    function database_connection()
    {
       $this->connect = new PDO("mysql:host=$Host;dbname=$DatabaseName", $DatabaseUsername, $DatabasePassword);
    }
function insert()    // Insert Function 
    {
        if(isset($_POST["Branch"]))
        {
            $form_data = array(
                ':Branch'=>$_POST['Branch'],
                ':Date'=>$_POST['Date'],
                ':Week'=>$_POST['Week'],
                ':Period'=>$_POST['Period'],
                ':Invoice_No'=>$_POST['Invoice_No'],
                ':Invoice_Reference'=>$_POST['Invoice_Reference'],
                ':Line_No'=>$_POST['Line_No'],
                ':Till_No'=>$_POST['Till_No'],
                ':Operator'=>$_POST['Operator'],
                ':Stock_Code'=>$_POST['Stock_Code'],
                ':Barcode'=>$_POST['Barcode'],
                ':Line_Quantity'=>$_POST['Line_Quantity'],
                ':Weight'=>$_POST['Weight'],
                ':Weight_Unit'=>$_POST['Weight_Unit'],
                ':Man_Weighed'=>$_POST['Man_Weighed'],
                ':Unit_ID'=>$_POST['Unit_ID'],
                ':Line_Price_Band'=>$_POST['Line_Price_Band'],
                ':Original_Sell'=>$_POST['Original_Sell'],
                ':Actual_Sell'=>$_POST['Actual_Sell'],
                ':Cost'=>$_POST['Cost'],
                ':Vat_Rate'=>$_POST['Vat_Rate'],
                ':Discount_Rate'=>$_POST['Discount_Rate'],
                ':Value_Goods'=>$_POST['Value_Goods'],
                ':Value_VAT'=>$_POST['Value_VAT'],
                ':Value_Sale'=>$_POST['Value_Sale'],
                ':Value_Cost'=>$_POST['Value_Cost'],
                ':Price_Override_Amount'=>$_POST['Price_Override_Amount'],
                ':Price_Overrided'=>$_POST['Price_Overrided'],
                ':Discounted'=>$_POST['Discounted'],
                ':Account_No'=>$_POST['Account_No'],
                ':Sub_Account_No'=>$_POST['Sub_Account_No'],
                ':Customer_Account'=>$_POST['Customer_Account'],
                ':Sub_Customer_Account'=>$_POST['Sub_Customer_Account'],
                ':Cust_Type_ID'=>$_POST['Cust_Type_ID'],
                ':Super_Department_ID'=>$_POST['Super_Department_ID'],
                ':Department_ID'=>$_POST['Department_ID'],
                ':Group_ID'=>$_POST['Group_ID'],
                ':Sub_Group_ID'=>$_POST['Sub_Group_ID'],
                ':Retail_Location_ID'=>$_POST['Retail_Location_ID'],
                ':Retail_Sub_Location_ID'=>$_POST['Retail_Sub_Location_ID'],
                ':Entry_Method'=>$_POST['Entry_Method'],
                ':End_Sale_Discount_Rate'=>$_POST['End_Sale_Discount_Rate'],
                ':Loyalty_Discount_Rate'=>$_POST['Loyalty_Discount_Rate'],
                ':Date_Time_Stamp'=>$_POST['Date_Time_Stamp']

            );
            $query = "
            INSERT INTO Lines 
            (Branch, Date, Week, Period, Invoice_No, Invoice_Reference, Line_No, Till_No, Operator, Stock_Code, Barcode, Line_Quantity, Weight, Weight_Unit, Man_Weighed, Unit_ID, Line_Price_Band, Original_Sell, Actual_Sell, Cost, Vat_Rate, Discount_Rate, Value_Goods, Value_VAT, Value_Sale, Value_Cost, Price_Override_Amount, Price_Overrided, Discounted, Account_No, Sub_Account_No, Customer_Account, Sub_Customer_Account, Cust_Type_ID, Super_Department_ID, Department_ID, Group_ID, Sub_Group_ID, Retail_Location_ID, Retail_Sub_Location_ID, Entry_Method, End_Sale_Discount_Rate, Loyalty_Discount_Rate, Date_Time_Stamp) VALUES 
            (:Branch, :Date, :Week, :Period, :Invoice_No, :Invoice_Reference, :Line_No, :Till_No, :Operator, :Stock_Code, :Barcode, :Line_Quantity, :Weight, :Weight_Unit, :Man_Weighed, :Unit_ID, :Line_Price_Band, :Original_Sell, :Actual_Sell, :Cost, :Vat_Rate, :Discount_Rate, :Value_Goods, :Value_VAT, :Value_Sale, :Value_Cost, :Price_Override_Amount, :Price_Overrided, :Discounted, :Account_No, :Sub_Account_No, :Customer_Account, :Sub_Customer_Account, :Cust_Type_ID, :Super_Department_ID, :Department_ID, :Group_ID, :Sub_Group_ID, :Retail_Location_ID, :Retail_Sub_Location_ID, :Entry_Method, :End_Sale_Discount_Rate, :Loyalty_Discount_Rate, :Date_Time_Stamp)
            ";
            $statement = $this->connect->prepare($query);
            if($statement->execute($form_data))
            {
                echo $statement ;
                $data[] = array(
                    'success'   =>  '1'
                );
            }
            else
            {
                var_dump($statement) ;
                $data[] = array(
                    'success'   =>  '0'
                );
            }
        }
        else
        {
            $data[] = array(
                'success'   =>  '0'
            );
        }
        return $data;
    }
}

调用函数:处理程序test_api.php //这确实包含Api.php的内容

if($_GET["action"] == 'insert')
{
    $data = $api_object->insert();
}

主机代码

这不会是最后一件事,因为我将从MSQL中提取构建数组并以这种方式发布,就像这样进行布局

<?php

$form_data = array(
    'Branch' => '1',
    'Date' => '8/11/2018 13:42:00',
    'Week' => '1',
    'Period' => '1',
    'Invoice_No' => '9999998',
    'Invoice_Reference' => '99999998',
    'Line_No' => '1',
    'Till_No' => '1',
    'Operator' => '99',
    'Stock_Code' => '123456',
    'Barcode' => '654321',
    'Line_Quantity' => '99',
    'Weight' => '',
    'Weight_Unit' => '',
    'Man_Weighed' => '',
    'Unit_ID' => '',
    'Line_Price_Band' => '1',
    'Original_Sell' => '99.99',
    'Actual_Sell' => '99.99',
    'Cost' => '9.99',
    'Vat_Rate' => '1',
    'Discount_Rate' => '',
    'Value_Goods' => '',
    'Value_VAT' => '',
    'Value_Sale' => '',
    'Value_Cost' => '',
    'Price_Override_Amount' => '',
    'Price_Overrided' => '',
    'Discounted' => '',
    'Account_No' => '',
    'Sub_Account_No' => '',
    'Customer_Account' => '',
    'Sub_Customer_Account' => '',
    'Cust_Type_ID' => '',
    'Super_Department_ID' => '',
    'Department_ID' => '',
    'Group_ID' => '',
    'Sub_Group_ID' => '',
    'Retail_Location_ID' => '',
    'Retail_Sub_Location_ID' => '',
    'Entry_Method' => '',
    'End_Sale_Discount_Rate' => '',
    'Loyalty_Discount_Rate' => '',
    'Date_Time_Stamp' => ''

);
$api_url = "localhost/Modules/API/Server/test_api.php?action=insert";  //change this url as per your folder path for api folder
$client = curl_init($api_url);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, $form_data);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
//     var_dump($response);
curl_close($client);

$result = json_decode($response, true);
echo $response ;
foreach($result as $keys => $values)
{
    if($result[$keys]['success'] == '1')
    {
        echo 'update';
    }
    else
    {
        echo 'error';
        echo $response ;
    }
}

目前它不起作用,我不确定为什么,因为它在使用较小的数据集时可以正常工作。 而且我的IDE尚未报告任何错误或错别字,不过那是其他事情,如果您发现错误,请说。

问题是,是否有更好的方法来处理大量列。

在以前的API中,我基本上只是将数据转储到txt并从分支程序中导入。所以这对我来说是全新的。

0 个答案:

没有答案