Skip to content

PHP Import SQL database extremely fast

PHP Import SQL database extremely fast

Sometimes when your using a shared host, there are many limitations, including file upload size or memory limit that you cannot control or modify. This will in turn affect whether you are able to import large databases into PhpMyAdmin. Hence, below is an alternative to use php code to import the database instead.
$db_host = 'localhost'; // change this
$db_name = 'db_name'; // change this
$db_username = 'db_username'; // change this
$db_password = 'db_password'; // change this

$sql = file_get_contents('mysqldump.sql'); //change this

$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
if (mysqli_connect_errno()) { /* check connection */
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* execute multi query */
if ($mysqli->multi_query($sql)) {
    echo "success";
} else {
   echo "error";
}
Code was referenced from a stackoverflow user that I do not remember anymore
Enjoyed the content ? Share it with your friends !
Published inDevelopmentProgramming

Be First to Comment

Leave a Reply

Your email address will not be published.