使用wpdb通过PhP插入SQL SERVER数据库

时间:2017-06-21 18:54:57

标签: php mysql sql-server database wordpress

我正在尝试将我从外部MySql数据库创建的php表单脚本转换为外部SQL Server数据库。我已经正确地复制了数据库,似乎在获取表单使用WPDB对象使用insert到新的SQL Server数据库时遇到了问题。两个数据库使用相同的创建脚本。

插入声明:

try {
$externalDB->insert('EmployeeApp.dbo.applicant', array(
            'first_name' => $first_name,
            'last_name' => $last_name,
            'middle_name' => $middle_name,
            'suffix' => $suffix,
            'nick_name' => $nick_name,
            'email' => $email,
            'idnumber' => $idnumber,
            'street_address' => $street_address,
            'city' => $city,
            'state' => $state,
            'zip' => $zip,
            'phone' => $phone,
            'ged' => $ged,
            'over_18' => $over_18,
            'previous_app' => $previous_app,
            'previous_app_date' =>$previous_app_date,
            'previous_emp' => $previous_emp,
            'previous_emp_date' => $previous_emp_date,
            'us_citizen' => $us_citizen,
            'visa' => $visa,
            'us_eligible' => $us_eligible,
            'date_avail' => $date_avail,
            'name_change' => $name_change,
            'name_change_info' => $name_change_info,
            'discharged' => $discharged,
            'military' => $military,
            'military_info' => $military_info,
            'high_school_name' => $high_school_name,
            'high_school_city' => $high_school_city,
            'high_school_state' => $high_school_state,
            'highest_grade_completed' => $highest_grade_completed,
            'additional_skills' => $additional_skills,
            'convicted'=> $convicted,
            'convicted_name' => $convicted_name,
            'convicted_date' => $convicted_date,
            'convicted_charge' => $convicted_charge,
            'convicted_sentence' => $convicted_sentence,
        ));
        $lastid = $externalDB->insert_id;

数据库连接对象:

try{
$externalDB = new wpdb(EMP_DB_USER,EMP_DB_PASS, EMP_DB_NAME, EMP_DB_HOST);
}catch(Exception $e){
echo $e->getmessage();
}

$wpdb已被声明为脚本顶部的全局,这在我连接到SQL Server数据库之前完美运行。 我想知道我是否需要不使用$externalDB->insert()与SQL或尝试不同的表调用,如'dbo.applicant'或只是'申请人'。不确定转换,也无法找到很多文档。

1 个答案:

答案 0 :(得分:0)

如果您look at the code,您将看到wpdb类仅连接到MySQL数据库。这是Wordpress的acknowledged limitation,虽然已经some attempts by third parties来纠正这种情况,但还没有任何官方发生过!