0

So i have a php script that i run directly from the browser and i get 2 errors:

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in...
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in...

In this script i make a query to select all blogs from my blog table:

$result = $this->query("
     SELECT *
     FROM blogs
");

And i get their feeds! So this script takes a little bit to execute, like 40secs. In my table i have 100 blogs and whenevery i run the script i get those 2 errors.

Important to know: In case i change the query like this i wont get those errors:

$result = $this->query("
     SELECT *
     FROM blogs
     LIMIT 0,70
");

So i am very sure that it has to do with some system admin settings. I use a shared host. So when i make operations for all 100 blogs i get errors and when i use only 70 blogs i dont.

Its like i lost the mysql conexion or something. The querys is not wrong, i printed them on the screen and checked them in phpmyadmin and they work.

One of the errors comes from here:

$result = $this->query("
    SELECT *
    FROM blogs_settings
");

$settings = $this->fetch_object($result);

return $settings->max_feeds;

This function is used to get the max feeds/page and i get that error, and the function has nothing wrong. I've set the max_execution_time to 120 and i dont know what else can i do.

I am very sure that lots of people got this error, and if there is somebody who knows, or guess what is the problem, i am sure that not only me will apreciate.

  • 1
    Have you looked at any of the [gazillion duplicates](http://stackoverflow.com/search?q=mysql_fetch_object%28%29%3A+supplied+argument+is+not+a+valid+MySQL+result+resource) and used `mysql_error` to figure out what's wrong? – deceze Jul 20 '12 at 07:59
  • 1
    possible duplicate of [Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result](http://stackoverflow.com/questions/795746/warning-mysql-fetch-array-supplied-argument-is-not-a-valid-mysql-result) – Richard Harrison Aug 01 '12 at 09:31
  • possible duplicate of [Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given error](http://stackoverflow.com/questions/11674312/warning-mysql-fetch-expects-parameter-1-to-be-resource-boolean-given-error) – j0k Aug 02 '12 at 12:07

1 Answers1

0

Given the fact that $result = $this->query(" SELECT * FROM blogs "); doesn't work but $result = $this->query(" SELECT * FROM blogs LIMIT 0,70 "); runs fine, and your other comments, have you looked at the maximum memory allowed as well?

The other thing that comes to mind (probably came to mind first really) is that a select * from blogs should NOT take 40 seconds to come back if you have a few hundred records. Just how BIG are these blogs you have?

Edit:

Now I think we are getting somewhere based on your comment of

*I dont get the error on the initial query. After i get all the feeds i keep them in an array with objects. And after that i make another query to get the number of feeds that will be displayed in the home page. That number i keep in table blogs_settings. And at that query i get the error*

In your object that is doing all the database connections, are you re-using the connection or are you opening a new connection to it each time? If so, are you properly releasing the connection to the database?

Fluffeh
  • 33,228
  • 16
  • 67
  • 80
  • max_memory_limit .. yes i thought of that. Currently its 64M but i cant change it with ini_set, i think i will ask the admin to increase that in order to see if thats the problem. Well i get 100 blogs from the database, and for each one of them i get their feeds using zend feed reader. So i take their feeds and after i have the last article post by every blog from the database, i arange them by hour. To be more clearly, i made a tool that make exactly the same thing that BlogList from blogger do. You add a list of blogs, and you see the last article post by them DESC by time of post. – Paul Alexandru Jul 20 '12 at 08:04
  • Just to make sure that I am getting this right, you run your `select * from blogs`, then you iterate through the results and get the feeds using the zend read feeder? Do you get the errors on the initial query, or while you are iterating through the results? – Fluffeh Jul 20 '12 at 08:07
  • I dont get the error on the initial query. After i get all the feeds i keep them in an array with objects. And after that i make another query to get the number of feeds that will be displayed in the home page. That number i keep in table blogs_settings. And at that query i get the error – Paul Alexandru Jul 20 '12 at 08:16
  • I do all this operations in a class that extends my model class where i establish the connection – Paul Alexandru Jul 20 '12 at 08:27
  • I found the answere, i will post it here in order for you to know. It was about: Default timeout for socket based streams (seconds) default_socket_timeout = 60 . This was set to 60 secs, and the admin increased it to 500 and now it works just fine. – Paul Alexandru Jul 20 '12 at 21:54