Дата не импортируется - PullRequest
       43

Дата не импортируется

0 голосов
/ 11 ноября 2019

Я работаю над приложением Excel для импорта. Я пытался импортировать файл Excel, но дата не сохраняется в базе данных. Другие текстовые поля сохраняются.

Структура таблицы

Table structure

<?php


use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Common\Type;

require_once ('connect.php');
require_once ('Spout/Autoloader/autoload.php');

if(!empty($_FILES['excelfile']['name']))
{
    // Get File extension eg. 'xlsx' to check file is excel sheet
    $pathinfo = pathinfo($_FILES['excelfile']['name']);

    // check file has extension xlsx, xls and also check
    // file is not empty
    if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
        && $_FILES['excelfile']['size'] > 0 )
    {
        $file = $_FILES['excelfile']['tmp_name'];

        // Read excel file by using ReadFactory object.
        $reader = ReaderFactory::create(Type::XLSX);

        // Open file
        $reader->open($file);
        $count = 0;

        // Number of sheet in excel file
        foreach ($reader->getSheetIterator() as $sheet)
        {

            // Number of Rows in Excel sheet
            foreach ($sheet->getRowIterator() as $row)
            {

                // It reads data after header. In the my excel sheet,
                // header is in the first row.
                if ($count > 0) {

                    // Data of excel sheet

                    $content = $row[1];
                    $title = $row[0];
                        $date = $row[2];
                     $language = $row[4];
                     $dt = $row[5];
                     $location = $row[3];
                     $new_date =  date_format($date,'Y-m-d H:i:s');
                     $new_dt = date_format($dt,'Y-m-d H:i:s');


                    //Here, You can insert data into database.
                    $qry = "INSERT INTO `icn`(`icn_title`, `icn_content`,`icn_date`,`icn_location`, `icn_language`, `updated_on`) VALUES ('$title','$content
t',`$new_date`,'$location','$language',`$new_dt`)";
                    $res = mysqli_query($con,$qry);

                }
                $count++;
            }
        }

        if($res)
        {
            echo "Your file Uploaded Successfull";
        }
        else
        {

            echo "Your file Uploaded Failed";
        }

        // Close excel file
        $reader->close();
    }
    else
    {
        echo "Please Choose only Excel file";
    }
}
else
{
    echo "File is Empty"."<br>";
    echo "Please Choose Excel file";
}

?>

Поле $ new_date и $ new_dt остается пустым после импорта листа Excel вбаза данных.

Это мой формат листа Excel

excel sheet format

Я пытался использовать тип в качестве "текста" для icn_dateи updated_on поля. Но все равно ничего не получалось.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...