Greetings to everyone again

There is a command to import the table in the bd-mysql site given to me in the last topic . There are 3 options:

  1. everything will work - and actually the data will be in the database / table of the site
  2. nothing will work - because This command is not allowed on the hosting.
  3. Nothing will work - if the command to register is incorrect (which often happens in my case)

(Yes, I understand those support taxis, but if there are many hosts, I want to do without phone calls)

Is it possible to check the support of this command on a hosting with any PHP script? Is it supported or not, and if it is supported, is there any error in the execution or not?

// теория, импорт таблицы в бд сайта system('mysql -u <user> -p<password> dbname < filename.sql'); // практика (myuser, mypass, mybase, filename.sql - пользователь и пароль пальзователя бд, сама бд, имя файла бд) system('mysql -u myuser -p mypass mybase < filename.sql'); 

    2 answers 2

    The system() function returns false on failure. That is, if it is prohibited, it should return false .

    If the function works, it returns the output of the command. This output can be checked for example on keywords like " error ". This can be done with a simple regular expression.
    It is advisable of course to examine the output of the mysql command and see what this command displays on success and completion and on completion with an error. Well, based on this already make up a regular expression.

    It seems to me that this is some kind of crutch decision. Maybe knowledgeable people will complement or correct me.

    • I understand about the error output. and about the solution, it exists, even indicated something similar for mysqli, only now for mysql it is hidden on the Internet - frank
    • @frank, why not switch to mysqli. It will be more modern. And mysql is officially outdated. news.php.net/php.internals/53799 Or is there no such possibility yet? - KryDos

    And what prevents to fill in the data through the script directly I do not use system commands?

    Here is the script for loading the dump into the database using the mysql functions) if you wish, you can transfer to PDO

     <?php // тут ваша конфа подключения к бд //файл с дампом $filename="file.sql"; $fp=fopen($filename,"r"); $contents=fread($fp,filesize($filename)); fclose($filename); $querys=preg_split("#;[\s]*\r\n)#is",$contents); foreach ($querys as $query) { if(!mysql_query($query)) exit(mysql_error()); } 

    works with properly compiled dump for MYSQL

    • Share the commands. then nothing will interfere. just import the entire table filename.sql lying on the hosting into the necessary database / site table (it is initially empty) with a great Internet found only a solution for mysqli php.su/forum/topic.php?forum=68&topic=732 - frank