0

I'm importing an SQL script from the Laravel command, the theme I don't know how to do for the data extraction since they are not the same attributes that the new database has.

At the moment I have been able to open and read the file but I can't think of how to get the data out. I thought of doing a seeder but the file also brings me the creation of tables.

At the moment this is what I have in code

$db = $this->argument('db');
        echo "Reading database from: $db \n";
        echo "\n validating extension \n";
        
        if (!preg_match('/(.*\.)(sql)$/',$db)) {
            echo "Format not valid \n";
            return;
        }

        echo "\n open script \n";
        $data = fopen('C:/sites/'.$db,"rb");
        $content = stream_get_contents($data);

        $output = ImportSQL::remove_comments($content);

        print_r($output);
        exit;
0

1 Answer 1

1

A suggestion would be to import your SQL file into some database and then play with it.

The below code is to write SQL file into same database.

$sql = file_get_contents('database_file.sql');
\DB::unprepared($sql);

You can create a temporary database for this purpose in config/database.php and then use the connection config like:

\DB::connection('mysql2')->unprepared($sql);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.