MySQL语法错误附近'' myguests''在第1行

时间:2014-12-22 11:23:59

标签: php mysql

我正在使用php获取MySQL数据库备份。但目前面临给定的错误。任何人都可以告诉我,我怎样才能摆脱这个错误。

<?php
    $db_server="server";
    $db_username="username";
    $db_password="";
    $db_database="database";
    $db_tablename="myguests";

    $db_connection = mysqli_connect("$db_server","$db_username","$db_password","$db_database");
    if(!$db_connection){
        die("Database connection error: ".mysqli_errorno());
    }  

    $db_backup= "/db_backup/";

    $db_select = "SELECT * INTO OUTFILE '$db_backup' FROM '$db_tablename'";

    $retval = mysqli_query($db_connection,$db_select);
    if(!$retval){
        die(/*"Could not take data backup: "*/mysqli_error($db_connection));
    }else{
        echo "Database backup successfully done";
    }
    mysqli_close($db_connection);   
?>

1 个答案:

答案 0 :(得分:0)

您已将数据库名称放在单引号中。

应该回来了。

变化:

$db_select = "SELECT * INTO OUTFILE '$db_backup' FROM '$db_tablename'";

要:

$db_select = "SELECT * INTO OUTFILE '$db_backup' FROM `$db_tablename`";

此外,不需要在这里加双引号,它也可以在没有它们的情况下工作:

$db_connection = mysqli_connect($db_server, $db_username, $db_password, $db_database);