1
我失去了这个错误:捕获的致命错误对象不能转换为字符串
Catchable fatal error Object of class DOMDocument could not be converted to string
这是我的PHP代码:
<?php
require_once('includes/mysqlConnect.php');
require_once('includes/utility.php');
//calling utility
$utility = new Utility();
//Creating a connection
$connection= new mySQL();
$connection->connect();
$getContent= file_get_contents('http://www.example.com/');
//echo $getContent;
//create a new DOMDocument Object
$doc= new DOMDocument();
//load HTML into DOMDoc
libxml_use_internal_errors(true);
$doc->loadHTML($getContent);
$utility->removeElementsByTagName('script', $doc);
$utility->removeElementsByTagName('style', $doc);
$utility->removeElementsByTagName('link', $doc);
echo $doc->saveHTML();
//Insert HTMl to DB
try
{
$result=$connection->db_query("CALL finalaggregator.insert_html('$doc')");
if ($result==0){
echo "<span style='color:red;'>Error! Data Saving Processes Unsuccessful</span>";
}
else {
echo "<span style='color:green;'>Data Successfully Saved!</span>";
}
}
catch (Exception $e){
echo "<span color='color:red;'>Error in Storing Data! Please Check Store Procedure.</span>";
}
?>
但总是显示
结束DOM Document could not be converted to string on line 29
我想将$ doc的值存储到数据库中。
当我试图从MySQL调用存储过程:
call finalaggregator.insert_html("<p>Testing123</p>");
它工作正常。
请帮帮我。我是新来的PHP。
我的存储过程如下:
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_html`(IN HTML LONGTEXT)
BEGIN
INSERT INTO finalaggregator.site_html (html) VALUES(HTML);
END
它不显示原来的错误,但是去“错误数据保存进程不成功!”。我能知道为什么吗? – Achilles
使用error_reporting()知道什么是错误,它显示“22527”。我可以知道如何解决这个问题吗? – Achilles
从error_reporting()返回的值“22527”是一个BitMask,表示错误报告级别。在这种情况下,它表示'E_ALL&〜E_DEPRECATED',因此所有错误都显示为'E_DEPRECATED'和'E_STRICT'(它不包括在'E_ALL'中)。 – Timo