PHP PEAR错误类'XML_Serializer'找不到?

时间:2017-05-27 09:21:41

标签: php xml xml-serialization pear

我需要将数组转换为XML文件。 我有以下代码:

<?php
$nouser = 'There is no user with that ID in the database.';
try {
$handler = new PDO('sqlite:Ebsco.db');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$name = '';
if (isset ($_POST['postname'])) {
    $name = $_POST['postname'];
};

$query = $handler->query('SELEcT * FROM Users WHERE ID='.$name);
$User = $query->fetch(PDO::FETCH_ASSOC);
if ($User) {

    $Serializer = &new XML_Serializer();
    $XML = $Serializer->serialize($User);
    print_r($XML);
print_r($Serializer);
}
else {
    echo $nouser;
}
}
catch (PDOException $e) {
    echo $nouser;
    die();
}
?>

该代码适用于检索数组并将其作为数组传递回html,但我遇到了PEAR XML_SERIALIZER的问题。 我已下载文件并将它们放在php / pear / xml文件夹中(我在主梨文件夹中留下的“包”除外,因为我不知道它的意图),并检查了phpinfo()确保include_path导致php / pear。 但是,当我添加XML_SERIALIZER时,我收到以下错误:

Fatal error: Class 'XML_Serializer' not found in...

我是PEAR的新手,所以我不确定我是否正确安装了所有内容(除了将文件放入库中,还有什么我需要做的吗?),或者这是否是由另一个问题引起的。 感谢名单

1 个答案:

答案 0 :(得分:0)

您需要手动包含该文件,除非您自己这样做,否则不会使用PEAR1包进行自动加载。

function infoValidation() {

$result = array('status' => false, 'message' => array());

$this->form_validation->set_error_delimiters('<div class="text-danger">','</div>');
if ($this->form_validation->run('company_registration')) {
        $config['upload_path']       = 'assets/uploads/';
        $config['allowed_types']     = 'gif|jpg|jpeg|png';

        $this->load->library('upload',$config); 
        $this->upload->initialize($config);
        if ($this->upload->do_upload('image'))
        {
            $data['upload_data'] = $this->upload->data('file_name');
            $image_name = $data['upload_data'];
            //$result['message'] = $this->upload->display_errors();
            //$result['status'] = false;
        }
        else
        {
            $image_name = '';   
        }

        $data = array(

            'email'         => $this->input->post('email'),
            'first_name'    => $this->input->post('firstname'),
            'last_name'     => $this->input->post('lastname'),
            'pincode'       => $this->input->post('pincode'),
            'state'         => $this->input->post('state'),
            'landmark'      => $this->input->post('landmark'),
            'address'       => $this->input->post('address'),
            'state'         => $this->input->post('state'),
            'image'         => $image_name,
            'joined_date'   => date('Y-m-d H:i:s')
            );


        $result['status'] = true;

        $this->Perfect_mdl->c_insert($data);


}else {


    foreach ($_POST as $key => $value) {

        $result['message'][$key] = form_error($key);
    }
}

echo json_encode($result);