6
I’m developing an app that has to access a list of websites stored in a database, upload all their links. It’s a test application but I’ve found a difficulty. The routine is this one:
function crawler() {
include_once './simple_html_dom.php';
//Coloquei este registro em um vetor para dar um exemplo
$sites = array("http://www.folhavitoria.com.br/");
//se eu descomentar a linha abaixo o erro acontece:
// $conecta = mysql_connect("localhost", "root", "");
foreach ($sites as $url){
$html = new simple_html_dom($url);
echo "<br>".$url."</br>";
foreach($html->find("a") as $link){
echo $link->href."<br/>";
}
unset($html);
}
}
Basically what this routine returns me is a series of links from within the main page of this site.
It turns out that when I put the function mysql_connect
, to be able to collect information from the bank at the time of running the following error message:
Fatal error: Call to a Member Function find() on a non-object in /var/www/html/Crawler/simple_html_dom.php on line 1113
updating responding to requests the function that is (next actually) of the 1113 line in simple_html_dom.php is as follows:
function find($selector, $idx=null, $lowercase=false)
{
return $this->root->find($selector, $idx, $lowercase);
}
I’ve tried several alternatives and I don’t know what else to do.
If you want to download Simple_html_dom for testing follow the link.: http://sourceforge.net/projects/simplehtmldom/files/
Post the code from line 1113 of the simple_html_dom.php file, please.
– Jorge B.
Basically the error says that the object was not created correctly so it has no method.
– rray
Actually the method exists, as I showed in the update I asked in the question. And it works if I don’t put the function mysql_connect() before...
– pdonatilio
brasofilo, to try to explain better, if I put instead an array with the page a routine to connect to the database and take the links from there, the system does not work...
– pdonatilio
You can put the code that has the snippet with mysql_connect, I tested I got this error passing a blank value to
simple_html_dom
– rray
Opa if you look I updated the question and put the additional data left the command that generates the commented error. abs.
– pdonatilio
If I’m not mistaken, that function
find()
gets aarray
and you try to read it as an object within the loop.– user4448
Opa thanks for the reply @luxu, really makes sense, however how to explain that the function works correctly if I do not insert the connection routine to the database?
– pdonatilio
Fatal error: Call to a member function find() on a non-object
this error occurs when you try to execute an incorrect query, check if the fields you are searching for in the database actually exist– RodrigoBorth
@luxu No. According to official documentation, the
find()
returns an "object array", see: "Find all Anchors, Returns an array of element Objects".– Guilherme Oderdenge
Thanks for the @Guilhermeoderdenge clarification. As I had said, the routine works correctly as long as I don’t call the database.
– pdonatilio
Opa Rodrigo thank you for the collaboration, the fields exist yes, the query has been revised, but I do not even call the query, as I said, just insert the function to connect with the database that the error happens.
– pdonatilio
Perform a
var_dump()
in$html
and post the result.– rray
Running var_dump($html) displayed this result:
object(simple_html_dom)#1 (19) { ["nodes"]=> array(34488) { [0]=> object(simple_html_dom_node)#2 (9) { ["nodetype"]=> int(5) ["tag"]=> string(4) "root" ["attr"]=> array(0) { } ["children"]=> NULL ["nodes"]=> NULL ["parent"]=> NULL ["_"]=> array(2) { [0]=> int(-1) [1]=> int(34488) } ["tag_start"]=> int(0) ["dom":"simple_html_dom_node":private]=> NULL } [1]=>
... @lost to me it seems the object is working properly.– pdonatilio
From what you’re saying, it seems to be the case mark an answer as accepted. Here we don’t put "solved" in the title. If you have an answer that really helped you, mark as accepted. If you came to the solution on your own, put in the solution as an answer. So content is more organized and easy to find for other people with similar problems in the future.
– bfavaretto
Thanks buddy, I’ll edit here. Thank you
– pdonatilio