我想从daatabase使用php导出sql和excel文件。尝试了在这里找到的所有薄片,但没有工作。
查看代码显示错误"严格标准:只应在C:\ xampp \ htdocs \ dan \ index.php中通过引用传递变量 在学校出口到〜/ one.sql"
时有一个警告<?php
$mysqlDatabaseName ='school';
$mysqlUserName ='root';
$mysqlPassword ='';
$mysqlHostName ='';
$mysqlExportPath ='one.sql';
$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > ~/' .$mysqlExportPath;
exec($command,$output=array(),$worked);
switch($worked){
case 0:
echo 'Database <b>' .$mysqlDatabaseName .'</b> successfully exported to <b>~/' .$mysqlExportPath .'</b>';
break;
case 1:
echo 'There was a warning during the export of <b>' .$mysqlDatabaseName .'</b> to <b>~/' .$mysqlExportPath .'</b>';
break;
case 2:
echo 'There was an error during export. Please check your values:<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;
}
?>
答案 0 :(得分:0)
mysqldump
试试这个
$output = array();
$worked = 2;
$command = "/usr/local/mysql/bin/mysqldump --opt";
if (!empty($mysqlHostName))
$command .= " -h$mysqlHostName";
$command .= " -u$mysqlUserName ";
if (!empty($mysqlPassword))
$command .= " -p'$mysqlPassword'";
$command .= " $mysqlDatabaseName > /tmp/$mysqlExportPath";
// your code goes here
调整mysqldump的路径并相应地导出文件夹