Codeigniter 2.1 및 Microsoft SQL Server를 사용하고 있습니다. 내가 데이터베이스에 UTF8 문자열을 삽입하려고하면 ??? 문자. 데이터베이스에 연결하려면 SqlSrv 드라이버를 사용하십시오.Insert-update utf8 string sql server + codeigniter
1
A
답변
1
SqlSrv 드라이버가 약간 변경되면 유니 코드 문제가 해결됩니다. 그냥 /system/database/sqlsrv/sqlsrv_driver.php 및 _insert 및 _update 기능 알렉스의 대답에 추가
/**
* @param mixed $value
*/
function _make_unicode($value){
if(is_string($value) && $value!="NULL")return "N".$value;
else return $value;
}
/**
* Insert statement
*
* Generates a platform-specific insert string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _insert($table, $keys, $values)
{
$values_string = "";
for($i=0;$i<count($values);$i++){
if($i==0){
$values_string.= $this->_make_unicode($values[$i]);
}else{
$values_string.= ", ".$this->_make_unicode($values[$i]);
}
}
return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES ({$values_string})";
}
// --------------------------------------------------------------------
/**
* Update statement
*
* Generates a platform-specific update string from the supplied data
*
* @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @param array the orderby clause
* @param array the limit clause
* @return string
*/
function _update($table, $values, $where)
{
foreach($values as $key => $val)
{
$valstr[] = $key." = ".$this->_make_unicode($val);
}
return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
}
// --------------------------------------------------------------------
1
(죄송 충분하지 명성 의견을)에 대한 코드를 대체 할 _make_unicode 기능 코드를 추가합니다. CodeIgniter 3.1.1과 동일한 기능이 있습니다.
_insert_batch
/**
* Insert batch statement
*
* Generates a platform-specific insert string from the supplied data.
*
* @param string $table Table name
* @param array $keys INSERT keys
* @param array $values INSERT values
* @return string|bool
*/
protected function _insert_batch($table, $keys, $values)
{
// Multiple-value inserts are only supported as of SQL Server 2008
if (version_compare($this->version(), '10', '>='))
{
foreach($values as &$value) {
$value = $this->_make_unicode($value);
}
return parent::_insert_batch($table, $keys, $values);
}
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
}
_update
/**
* Update statement
*
* Generates a platform-specific update string from the supplied data
*
* @param string $table
* @param array $values
* @return string
*/
protected function _update($table, $values)
{
foreach ($values as &$value) {
$value = $this->_make_unicode($value);
}
$this->qb_limit = FALSE;
$this->qb_orderby = array();
return parent::_update($table, $values);
}
관련 문제
- 1. Sql Server String Comparison
- 2. iOS : decode utf8 string
- 3. CodeIgniter SQL Server 데이터베이스 오류
- 4. Codeigniter 2.0.3 with SQL Server 활성 레코드
- 5. SQL Server 2005에서 UTF8 (XML) 데이터를 가장 효율적으로 읽습니다.
- 6. string to varchar C#/SQL Server
- 7. CodeIgniter 액티브 레코드 (String In Not String)
- 8. Server Check Codeigniter
- 9. CodeIgniter - 이스케이프 SQL 문
- 10. CodeIgniter - SQL 이스케이프
- 11. SQL 구문에 오류가 있습니다. MariaDB server + codeigniter + LOAD DATA INFILE
- 12. UTF8 호환성
- 13. EF4/SQL Server 2008에서 "datetime> string"성능 문제가있는
- 14. Codeigniter 1.7.2는 SQL Server를 지원합니까?
- 15. UTF8
- 16. UTF8
- 17. UTF8
- 18. SQL + Ion Auth + CodeIgniter?
- 19. CodeIgniter 자체 조인이 SQL
- 20. codeigniter with SQL
- 21. Codeigniter sql binding
- 22. 온도 테이블이있는 Codeigniter SQL
- 23. Codeigniter -보기에서 SQL 쿼리
- 24. Codeigniter SQL 다목적 쿼리
- 25. json_encode utf8
- 26. string sql select
- 27. sql queries, java string
- 28. CakePHP의 SQL Server 오류
- 29. nodejs- mysql이 잘못되었습니다. utf8 characer string 파일에 데이터를로드하십시오.
- 30. C++ 11에서 좋은 std :: string 크로스 플랫폼 UTF8 대안?