在具有空格不起作用的字段中插入PHP PDO

时间:2014-01-29 16:42:14

标签: php mysql pdo insert

我对此有点困惑,我认为问题是在带空格的字段中插入数据,这是正确的方法吗?

我得到的错误信息是:

数据库错误:SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配

 $consulta = "INSERT INTO $table 
        (Title, Title_Short, City, `Department / Branch`)
        VALUES (:Title, :Title_Short, :City, :`Department / Branch`)";

        $result = $db->prepare($consulta);

    $result->execute(array(
        ":Title" => getTitle($url_job),
        ":Title_Short" => getTitle_Short($url_job),
        ":City" => getTitle($url_job),
        ":Department / Branch" => getTitle_Short($url_job),

        ));

1 个答案:

答案 0 :(得分:1)

占位符不允许使用特殊字符。使用:

$consulta = "INSERT INTO $table 
    (Title, Title_Short, City, `Department / Branch`)
    VALUES (:Title, :Title_Short, :City, :DeptBranch)";

$result = $db->prepare($consulta);

$result->execute(array(
    ":Title" => getTitle($url_job),
    ":Title_Short" => getTitle_Short($url_job),
    ":City" => getTitle($url_job),
    ":DeptBranch" => getTitle_Short($url_job),

));