设置名称和排序规则UTF8在SimpleXML或MySQL

时间:2015-06-27 08:50:44

标签: php mysql xml utf-8 simplexml

我是gettin XML数据,其头部已设置utf8:

<?xml version="1.0" encoding="utf-8"?>

下载使用 CURL ,并使用UTF8字符正确下载。

解析使用此代码使用 SimpleXML 下载 xml 文件:

<?php

class XMLParser {

public function __construct(){
}

public function parseFile($path){
    $xml = '';

    if(!is_null($path)){
        $file = file_get_contents($path);
        if(!is_null($file)){
            $xml = new SimpleXMLElement($file);
        }
        else{
            echo 'there is no file';
        }
    }
    else{
        echo 'Wrong path!';
    }
    return $xml;
}

} ?&GT;

发送数据库,调用 PDO 存储过程,连接脚本定义了utf8:

$this->PDO->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");

每个表都有 utf8_general_ci

但在表格中就是这样的字符:

  

LeóndeHuánuco - Cienciano

更新! CREATE TABLE代码:

CREATE TABLE IF NOT EXISTS `jcjdkdtaur`.`fixtures` (
  `Id` INT(32) NOT NULL,
  `UpdatedDate` varchar(100) DEFAULT NULL,
  `DateTime` datetime NULL DEFAULT NULL,
  `Date` date NULL DEFAULT NULL,
  `Time` time NULL DEFAULT NULL,
  `Status` VARCHAR(40) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL DEFAULT NULL,
  `League` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL DEFAULT NULL,
  `LeagueID` INT(11) DEFAULT NULL,
  `SportID` tinyint DEFAULT 1,
  `SportName` varchar(30) DEFAULT 'football',
  `Cup` varchar(20) DEFAULT NULL,
  `Country` VARCHAR(60) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL DEFAULT NULL,
  `EventName` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL DEFAULT NULL,
  `HomeTeam` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL DEFAULT NULL,
  `HomeTeam_Id` INT(11) NULL DEFAULT NULL,
  `AwayTeam` VARCHAR(255) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NULL DEFAULT NULL,
  `AwayTeam_Id` INT(11) NULL DEFAULT NULL,
  PRIMARY KEY (`Id`,`HomeTeam_Id`,`AwayTeam_Id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

INSERT STORE PROCEDURE我从PHP打电话:

DROP PROCEDURE IF EXISTS insupd_Fixtures;
DELIMITER //
CREATE PROCEDURE insupd_Fixtures(IN p_id int(32), IN p_updated varchar(100), IN p_datetime datetime, IN p_date date, 
IN p_time time, IN p_status varchar(40),IN p_league varchar(255),IN p_leagueid int(11), IN p_sportid tinyint, IN p_sportname varchar(30), 
IN p_cup VARCHAR(20), IN p_country VARCHAR(60),IN p_eventname varchar(255),IN p_hometeam varchar(255),IN p_hometeam_id int(11),
IN p_awayteam varchar(255),IN p_awayteam_id int(11)
)
BEGIN
INSERT INTO fixtures(`Id`,`UpdatedDate`,`DateTime`,`Date`,`Time`,`Status`,`League`,`LeagueID`,`SportID`,`SportName`,`Cup`,`Country`,`EventName`,
`HomeTeam`,`HomeTeam_Id`,`AwayTeam`,`AwayTeam_Id`)
VALUES
(p_id,p_updated, p_datetime, p_date, p_time, p_status,p_league, p_leagueid, p_sportid, p_sportname, p_cup,p_country,
p_eventname,p_hometeam,p_hometeam_id,p_awayteam,p_awayteam_id)
ON DUPLICATE KEY UPDATE
Id=p_id,
UpdatedDate = p_updated,
DateTime=p_datetime,
Date=p_date,
Time=p_time,
Status=p_status,
League=p_league,
LeagueID = p_leagueid,
SportID = p_sportid,
SportName = p_sportname,
Cup=p_cup,
Country=p_country,
EventName=p_eventname,
HomeTeam=p_hometeam,
HomeTeam_Id=p_hometeam_id,
AwayTeam=p_awayteam,
AwayTeam_Id=p_awayteam_id;
END //

0 个答案:

没有答案