-2

I want to export all of tables of my db in sql file using php with encoding UTF-8 whats the best way! whats the code! thank you

Pedramch
  • 81
  • 1
  • 8

1 Answers1

1

Start your query after this:

$db = new MySQLi("host", "username", "password", "db");

if(!$db)
{
    die("your_error_msg" . mysqli_error($db));
}

$db->set_charset("utf8");'

EDIT

<?php
    //ENTER THE RELEVANT INFO BELOW
    $mysqlDatabaseName ='xxxxxx';
    $mysqlUserName ='xxxxxxx';
    $mysqlPassword ='myPassword';
    $mysqlHostName ='xxxxxxxx.net';
    $mysqlExportPath ='chooseFilenameForBackup.sql';

    //DO NOT EDIT BELOW THIS LINE
    //Export the database and output the status to the page
    $command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' --default-character-set=utf8 ' .$mysqlDatabaseName .' > ~/' .$mysqlExportPath;
    exec($command);
 ?>

From: export database using php code in .sql Extension?, but I added the --default-character-set=utf8 part

Community
  • 1
  • 1
solid_luffy
  • 361
  • 2
  • 15