Loading CSV into MySQL using OOP PHP I need to make a simple CSV->MySQL script in OOP and I was wondering if there's anything I am doing wrong in a object-oriented sense.

I have a file name db.php where I connect to MySQL via MySQLi and then I have another class where I load a csv file into MySQL like this:

class csv extends Database {

        public $file = null;

   function __construct() {

            if(count($_SERVER["argv"]) &gt; 1){
                $this-&gt;file = $_SERVER["argv"][1];
            }else{
                $this-&gt;file = "stock.csv";
            }

            $this-&gt;db = $db;

        }

        function saveCSVtoDB(){
            //opens the file
            $fp = fopen($this-&gt;file, "r");



            $db = Database::getInstance();
            $mysqli = $db-&gt;getConnection();

            $result = $mysqli-&gt;query("LOAD DATA LOCAL INFILE 'file.csv'
                                           IGNORE INTO TABLE products
                                               CHARACTER SET UTF8
                                        FIELDS TERMINATED BY ',' 
                                         LINES TERMINATED BY '\n'
                                              IGNORE 1 LINES
                                              (code, name, desc, stock, price, @avai)
                                                         SET available = IF(@avai LIKE '%yes%', 1, 0)
                                               ");

            if($result){
                echo "success";
            }else{
                die("error");
            }

        }
}
So I would recommend to not extend the CSV parser from the Database class. 
Instead The CSV parser should get the Database per dependency injection through 
the constructor. Also I would not recommend to access gobal vars like $_SERVER 
in a class. Here an example how you could do that:

class CSVParser
{
    protected $file;
    protected $database;

    public function __construct($file, Database $db)
    {
        $this-&gt;file = $file;
        $this-&gt;db = $db;
    }

    public function saveCSVtoDB()
    {
        // @TODO import CSV to DB
    }
}


And you could use the class with:

$file = isset($_SERVER["argv"][1]) ? $_SERVER["argv"][1] : "stock.csv";

$parser = new CSVParser($file, Database::getInstance());
$parser-&gt;saveCSVtoDB();