Click here to Skip to main content
15,886,689 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: How do I calculate the column in PHP union all function Pin
SeanChupas13-May-21 1:51
SeanChupas13-May-21 1:51 
QuestionPHP :: VSCode always opens a new blank window (untitled-1) Pin
Gustavo Laufer AU4-Apr-21 22:00
Gustavo Laufer AU4-Apr-21 22:00 
AnswerRe: PHP :: VSCode always opens a new blank window (untitled-1) Pin
SeanChupas5-Apr-21 3:15
SeanChupas5-Apr-21 3:15 
Questioni have this errors in my project please i need help Pin
frank saki24-Mar-21 11:55
frank saki24-Mar-21 11:55 
AnswerRe: i have this errors in my project please i need help Pin
Richard Deeming24-Mar-21 22:12
mveRichard Deeming24-Mar-21 22:12 
QuestionHow can I echo the numbers using list() function in foreach loop? Pin
Best Tutor24-Feb-21 9:33
Best Tutor24-Feb-21 9:33 
QuestionRe: How can I echo the numbers using list() function in foreach loop? Pin
Richard MacCutchan24-Feb-21 21:56
mveRichard MacCutchan24-Feb-21 21:56 
QuestionHow to import csv using php code Pin
Mohammed Hudair16-Feb-21 6:24
Mohammed Hudair16-Feb-21 6:24 
I would to import csv products to mysql using below codes but i don't know what framework to use
the data is large more than 100000 products





<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use PDO;

class ImportProducts extends Command
{
    /**
     * @var string
     */
    protected $signature = 'import:products';

    /**
     * @var string
     */
    protected $description = 'Imports products into database';

    /**
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @return mixed
     */
    public function handle()
    {
        // Rename from products1.csv into products2.csv to import a file with slightly different data
        $contents = file_get_contents('products.csv');
        $lines = explode("\n", $contents);

        $i = 0;

        foreach ($lines as $line) {

            $fields = explode(';', $line);

            $pdo = new PDO('mysql:dbname=coding_challenge;host=172.0.0.1;port=3306', 'root', 'secret');

            $query = $pdo->prepare("SELECT COUNT(*) AS c from products WHERE id=?");
            $result = $query->execute([$fields[0]]);
            if($query->rowCount()) {
                $pdo->query('DELETE FROM products WHERE id = "' . $fields[0] . '"');
                print('Deleted existed product to be updated.');
            }

            $query = $pdo->prepare('INSERT INTO products (id, name, sku,status,variations, price, currency) VALUES (?, ?, ?, ? , ? , ?, ?)');
            $result = $query->execute([$fields[0], ($fields[4] ?? ''), ($fields[5] ?? ''), ($fields[6] ?? ''), ($fields[9] ?? ''), ($fields[10] ?? '') ]);

            // TODO: Soft delete no longer exist products from the database.

            $i++;
        }

        die('Updated ' . $i . ' products.');
    }
}



<?php

namespace App\Console;

use App\Console\Commands\ImportProducts;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        ImportProducts::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

QuestionHow to code login page in html css php Pin
Member 150661826-Feb-21 1:01
Member 150661826-Feb-21 1:01 
AnswerRe: How to code login page in html css php Pin
Richard MacCutchan6-Feb-21 1:27
mveRichard MacCutchan6-Feb-21 1:27 
QuestionPosting dropdown value to database Pin
Member 1505550825-Jan-21 2:27
Member 1505550825-Jan-21 2:27 
AnswerRe: Posting dropdown value to database Pin
Richard Deeming25-Jan-21 4:04
mveRichard Deeming25-Jan-21 4:04 
GeneralRe: Posting dropdown value to database Pin
Member 1505550825-Jan-21 6:31
Member 1505550825-Jan-21 6:31 
GeneralRe: Posting dropdown value to database Pin
Richard Deeming25-Jan-21 21:28
mveRichard Deeming25-Jan-21 21:28 
GeneralRe: Posting dropdown value to database Pin
Member 1505550825-Jan-21 21:57
Member 1505550825-Jan-21 21:57 
GeneralRe: Posting dropdown value to database Pin
Richard Deeming25-Jan-21 22:36
mveRichard Deeming25-Jan-21 22:36 
GeneralRe: Posting dropdown value to database Pin
Member 1505550825-Jan-21 22:58
Member 1505550825-Jan-21 22:58 
GeneralRe: Posting dropdown value to database Pin
Richard Deeming26-Jan-21 2:10
mveRichard Deeming26-Jan-21 2:10 
GeneralRe: Posting dropdown value to database Pin
Member 1505550826-Jan-21 3:27
Member 1505550826-Jan-21 3:27 
GeneralRe: Posting dropdown value to database Pin
jsc4226-Jan-21 3:40
professionaljsc4226-Jan-21 3:40 
GeneralRe: Posting dropdown value to database Pin
Richard Deeming26-Jan-21 3:44
mveRichard Deeming26-Jan-21 3:44 
QuestionHTML Form...Submit to E-Mail Pin
Member 149874928-Nov-20 20:04
Member 149874928-Nov-20 20:04 
QuestionCan't import pfx. Pin
ArturNoubel3-Nov-20 8:27
ArturNoubel3-Nov-20 8:27 
AnswerRe: Can't import pfx. Pin
Richard MacCutchan2-Nov-20 3:18
mveRichard MacCutchan2-Nov-20 3:18 
GeneralRe: Can't import pfx. Pin
ArturNoubel3-Nov-20 7:54
ArturNoubel3-Nov-20 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.