简体   繁体   English

如何使用php处理xml中的mysql_connect错误

[英]How to handle mysql_connect error in xml using php

I trying to check login credential via xml using php,Following is the piece of code to check DB connection 我试图使用php通过xml检查登录凭据,以下是检查数据库连接的代码段

$con = mysql_connect($host,$user,$pass) or die("<result><message>Could not connect to host</message></result>");

if connection fails throws error like 如果连接失败则抛出错误

 "XML Parsing Error: junk after document element
Location: http://test.study.com/test/services/checkLogindata.php
Line Number 2, Column 1: ...." 

在此处输入图片说明

I dont want that message,i want to display simply like , 我不想要那条消息,我想简单地显示为

<result>
<message>Could not connect to host</message>
</result>

Is it possible to display like above, if yes kindly help me 是否可以像上面那样显示,如果可以,请帮我

Finally i found one solution by giving "error_reporting(0);" 最后,我给出了“ error_reporting(0);”找到了一个解决方案。 before mysql_connect(); 在mysql_connect()之前;

you should add xml header line like this 您应该像这样添加xml标头行

<?xml encoding="ISO-8859-1" version="1.0"?>

Try this 尝试这个

die("<?xml encoding='ISO-8859-1' version='1.0' ?>
      <result><message>Could not connect to host</message></result>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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