2016-05-25 9 views
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 

答えて

0

あなたは単にあなたのクエリ内の文字列としてDOMDocumentのインスタンスを使用することはできません。最初に明示的にHTML文字列に変換する必要があります。

$html = $doc->saveHTML(); 
$result = $connection->db_query("CALL finalaggregator.insert_html('$html')"); 
+0

「エラー!データの保存プロセスが失敗しました」に移動します。理由をお聞かせいただけますか? – Achilles

+0

error_reporting()を使ってエラーが何であるかを知ると、 "22527"と表示されます。これを解決する方法は分かりますか? – Achilles

+0

'error_reporting()'から返された値 '22527 'はエラー報告レベルを表すBitMaskです。この場合、 'E_ALL&〜E_DEPRECATED'を表しているので、すべてのエラーは' E_DEPRECATED'と 'E_STRICT'(' E_ALL'には含まれていません)のためにexecptで表示されます。 – Timo

関連する問題