How to impost a .mysql to phpmyadmin using php

Discussion in 'PHP' started by Mohd Shibli, Sep 26, 2016.

  1. #1
    I am building an application and in that i want the users to install it first, so during installation i want the php script to import my .sql file to automatically setting up database.....any suggestions plz help
     
    Mohd Shibli, Sep 26, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    You can export the SQL, but you'll probably have to rewrite the raw SQL a bit to being parsed by PHP.

    The installation isn't that much more than having the user provide his database username / login, and any other specifics - like port, database name etc.

    So you'll need a form for the user to input information, preferably storing that information in a config-file somewhere, then connect to the database, create the tables, populate them and so on.
     
    PoPSiCLe, Sep 26, 2016 IP
  3. Einheijar

    Einheijar Well-Known Member

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    165
    #3
    
    $sql= file_get_contents('test.sql');
    mysqli_multi_query($sql);
    //or with PDO
    $db->query($sql)
    
    Code (markup):
    That works fine for me
     
    Einheijar, Oct 2, 2016 IP