简体   繁体   中英

using wpdb to insert into SQL SERVER database with PhP

I am attempting to convert a php form script I created from an external MySql database to an external SQL server database. I have properly copied the database over and just seem to be having a problem getting the form to use the WPDB object to use insert into the new SQL server database. The same creation script was used for both databases.

The insert statement:

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;

The database connection object:

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

$wpdb has been declared as a global at the top of the script and this was working perfectly before I connected to a SQL server database. I am wondering if I need to not use $externalDB->insert() with SQL or try a different table call such as just 'dbo.applicant' or just 'applicant'. Not sure about the transition and can't find a lot of documentation on it.

If you look at the code , you will see that the wpdb class connects only to MySQL databases. This is an acknowledged limitation of Wordpress, and although there have been some attempts by third parties to rectify the situation, nothing official has happened yet!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM