SQL预处理语句以大写形式插入数据库

时间:2017-03-08 14:50:19

标签: php mysql prepared-statement

我有这个函数,它向我的数据库插入一些值。插入的值很好,但我试图将它们插入大写但不起作用。如果在print_r值以大写字母打印后使用for loop。但是在我的数据库中,它不是以大写形式存储的。有没有人经历过这样的问题?

function tryToInsertRow($mCurrentRowData){

    global $connection;

   // Make Data Uppercase
   for($i = 0; $i < sizeof($mCurrentRowData); $i++){
      $mCurrentRowData[$i] = strtoupper($mCurrentRowData[$i]);
   }



    $query_insert = "INSERT INTO main_db (contact_id, customer_code, customer_name, territory, firstname, lastname, contact_type_description, contact_is_primary, mailing_street, mailing_postal_code, mailing_city, mailing_country, email, mobile_phone, phone) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

    if ($stmt = mysqli_prepare($connection, $query_insert)) {


        // bind parameters for markers
        if (!mysqli_stmt_bind_param($stmt, "sssssssdsssssss", $mCurrentRowData[0] ,$mCurrentRowData[1] ,$mCurrentRowData[2] ,$mCurrentRowData[3] , $mCurrentRowData[4] ,$mCurrentRowData[5] ,$mCurrentRowData[6] ,$mCurrentRowData[7] ,$mCurrentRowData[8] ,$mCurrentRowData[9] ,$mCurrentRowData[10] ,$mCurrentRowData[11] ,$mCurrentRowData[12] ,$mCurrentRowData[13] ,$mCurrentRowData[14])) {
            error_log(mysqli_error($connection));
            return false;
        }

        //execute query
        if (!mysqli_stmt_execute($stmt)) {
            error_log(mysqli_error($connection));
            return false;
        }

        mysqli_stmt_close($stmt);
        return true;

    } else {
        error_log(mysqli_error($connection));
        return false;
    }


}

主数据库创建:

CREATE TABLE `main_db` (
 `contact_id` varchar(255) NOT NULL,
 `customer_code` varchar(255) NOT NULL,
 `customer_name` varchar(255) DEFAULT NULL,
 `territory` varchar(255) DEFAULT NULL,
 `firstname` varchar(255) DEFAULT NULL,
 `lastname` varchar(255) DEFAULT NULL,
 `contact_type_description` varchar(255) DEFAULT NULL,
 `contact_is_primary` int(1) DEFAULT NULL,
 `mailing_street` varchar(255) DEFAULT NULL,
 `mailing_postal_code` varchar(255) DEFAULT NULL,
 `mailing_city` varchar(255) DEFAULT NULL,
 `mailing_country` varchar(255) DEFAULT NULL,
 `email` varchar(255) DEFAULT NULL,
 `mobile_phone` varchar(255) DEFAULT NULL,
 `phone` varchar(255) DEFAULT NULL,
 `is_processed` int(1) NOT NULL DEFAULT '0',
 UNIQUE KEY `contact_id` (`contact_id`,`customer_code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

0 个答案:

没有答案