last day (14 days later) » 

12:47
-4
Q: Public function fetch limited?

uollaaOk guys, I have strange thing happening with fetch function. Here is the deal: I'm fetching data from DB in seperate file (via classes) like: class Adds extends Core { public function fetchAdds() { //query db $this->query("SELECT adds_id, adds_title, adds_link, adds_fi...

What does it scream about? And maybe once used the info from certain method, you can free the result?
@FDL I'm not sure I understand, but I don't think I do, It is a simple PHP code (in several files). One interacts with DB, others use the data.. (but only up to 9 times)
The interaction with the DB is the interesting part, maybe the limit is set somewhere there. The core class contains this logic, right? Post us? Also what error do you get
@RoyalBg how do I do that?
@RoyalBg I don't get any errors, just empty area where data should be
Show us what Core contains
12:47
class Core {
protected $db, $result;
private $rows;

public function __construct(){
$this->db = new mysqli('');
$this->db->set_charset('utf8');
}

public function query ($sql){
$this->result = $this->db->query($sql);
}

public function rows(){
for($x =1; $x<= $this->db->affected_rows; $x++){
$this->rows[] = $this->result->fetch_assoc();
}
return $this->rows;
}
}
this is the whole core file
THere's something wrong with the rows() method, let me test it and if I am able will provide a fix
this is the index file
//Categories
$cats = new Cats();
$cats_x = $cats->fetchCats();

//TOP
$posts_ho = new Posts_ho();
$posts_hox = $posts_ho->fetchPosts_ho();

//SUB 3
$posts_hoa = new Posts_hoa();
$posts_hoax = $posts_hoa->fetchPosts_hoa();

//SUB 3 MO
$posts_hoam = new Posts_hoam();
$posts_hoamx = $posts_hoam->fetchPosts_hoam();

//BOTOM
$posts_hi = new Posts_hi();
$posts_hix = $posts_hi->fetchPosts_hi();

//BOTOM SUB 3
$posts_hia = new Posts_hia();
$posts_hiax = $posts_hia->fetchPosts_hia();

//Galeries
$galsx = new Galsx();
notice that there are 10 of calls
only first 9 works
which one does not work, Adds?
I tested it by rearranging the order
FDL
FDL
Instead of all this:
for($x =1; $x<= $this->db->affected_rows; $x++){
$this->rows[] = $this->result->fetch_assoc();
}
12:51
the last one, allways
FDL
FDL
why don't you use $this->db->fetchAll()
will try now, pls wait sec
I think the whole for loop should be taken out
FDL, it's mysqli object, not PDO
FDL
FDL
oh yeh my bad, didnt see that
$this->db->fetchAll()
gives me interntal server error
500
FDL
FDL
12:56
It should probably be $this->result->fetch_all()
was me being hasty, thought it was PDO but as Royal pointed out, it's mysqli
try $this->rows = $this->result->fetch_all()
FDL, I'm not so aware with mysqli native methods, but couldn't it be this way?
public function rows() {
while ($row = $this->result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
I really don't find a point of using internal property $rows here
tried taking out the intire for loop, now no data gets returned
FDL
FDL
a while is more suitable than that for loop, for sure... just trying to make use of the fetch_all method, since it removes the need for any loop at all
Royal, nop, error 500 again
@FDL where do i try it, insted of for loop?
I think it was his point, yep
public function rows() {
$this->rows = $this->result->fetch_all();

return $this->rows;
}
13:07
internal error 500 again
thank you for your help
i'll manage under 10 instances
will rearrange fetching
btw. where do you get the wrapper from
you mean this core.php code?
yep
you can google for mysqli wrapper, several people have already uploaded in github for example, a more efficient wrappers, where you can select,update,insert and return rows, much easier
13:10
i really don't know no more, i use it for more than year or so, found it the best way so far for interaction with db, didn't have any problems, it gives me the flexibility
and i place it under httacces
in sepearate file
and it is easy for changes
.
will do
thank you
for your time
sorry for disability to help, good luck in refactoring the wrapper, it might save you time in future :))
well, i'm semibeginner :D
so, any help is wellcomed
:)
(i mostly do design, but sometimes people want web) and I hate wordpress and joomla etc
soo, php :D

last day (14 days later) »