严格标准:只有变量应该在 /main_dir/sub_dir/backup.php 中通过引用传递
Strict Standards: Only variables should be passed by reference in /main_dir/sub_dir/backup.php
我能够从浏览器 运行 脚本并备份我的 mysql 数据库,但是当我尝试使用 cron 作业执行此操作时,出现错误:
Strict Standards: Only variables should be passed by reference in
/main_dir/sub_dir/backup.php Warning: Using a password on the command
line interface can be insecure.
有什么建议吗?而且,为什么密码警告?
<?php
//Enter your database information here and the name of the backup file
$mysqlDatabaseName ='xxxxxxxxxxxxxx';
$mysqlUserName ='xxxxxxxxxxxxxx';
$mysqlPassword ='xxxxxxxxxxxxxx_';
$mysqlHostName ='xxxxxxxxxxxxxx';
$mysqlExportPath ='xxxxxxxxxxxxxx.sql';
//Please do not change the following points
//Export of the database and output of the status
$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > ' .$mysqlExportPath;
exec($command,$output=array(),$worked);
switch($worked){
case 0:
echo 'The database <b>' .$mysqlDatabaseName .'</b> was successfully stored in the following path '.getcwd().'/' .$mysqlExportPath .'</b>';
break;
case 1:
echo 'An error occurred when exporting <b>' .$mysqlDatabaseName .'</b> zu '.getcwd().'/' .$mysqlExportPath .'</b>';
break;
case 2:
echo 'An export error has occurred, please check the following information: <br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$mysqlDatabaseName .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$mysqlUserName .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$mysqlHostName .'</b></td></tr></table>';
break;
}
?>
应该允许我使用 cron 作业进行 mysql 数据库备份。
对于第一个错误,更改
exec($command,$output=array(),$worked);
到
$output = array();
exec($command,$output,$worked);
由于exec()
的第二个参数是一个引用参数,它必须是一个变量,而不是表达式。
请参阅 Suppress warning messages using mysql from within Terminal, but password written in bash script 了解许多防止在命令行上使用密码的警告的方法。
我能够从浏览器 运行 脚本并备份我的 mysql 数据库,但是当我尝试使用 cron 作业执行此操作时,出现错误:
Strict Standards: Only variables should be passed by reference in /main_dir/sub_dir/backup.php Warning: Using a password on the command line interface can be insecure.
有什么建议吗?而且,为什么密码警告?
<?php
//Enter your database information here and the name of the backup file
$mysqlDatabaseName ='xxxxxxxxxxxxxx';
$mysqlUserName ='xxxxxxxxxxxxxx';
$mysqlPassword ='xxxxxxxxxxxxxx_';
$mysqlHostName ='xxxxxxxxxxxxxx';
$mysqlExportPath ='xxxxxxxxxxxxxx.sql';
//Please do not change the following points
//Export of the database and output of the status
$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > ' .$mysqlExportPath;
exec($command,$output=array(),$worked);
switch($worked){
case 0:
echo 'The database <b>' .$mysqlDatabaseName .'</b> was successfully stored in the following path '.getcwd().'/' .$mysqlExportPath .'</b>';
break;
case 1:
echo 'An error occurred when exporting <b>' .$mysqlDatabaseName .'</b> zu '.getcwd().'/' .$mysqlExportPath .'</b>';
break;
case 2:
echo 'An export error has occurred, please check the following information: <br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$mysqlDatabaseName .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$mysqlUserName .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$mysqlHostName .'</b></td></tr></table>';
break;
}
?>
应该允许我使用 cron 作业进行 mysql 数据库备份。
对于第一个错误,更改
exec($command,$output=array(),$worked);
到
$output = array();
exec($command,$output,$worked);
由于exec()
的第二个参数是一个引用参数,它必须是一个变量,而不是表达式。
请参阅 Suppress warning messages using mysql from within Terminal, but password written in bash script 了解许多防止在命令行上使用密码的警告的方法。