Note my main answer is at the bottom (IF you can't edit this function) but I have put in alternative answers as am unclear from OP as to if the function can/should be edited.
Edit this function
Your declared function has:
public function __getalldata($tablename,...,$limit = 200 ...){ ... }
Where the reference given in various answers here appearing to be adjusting this default value - the simplest solution is to NOT edit the default but set a special case and explicitly check for if $limit
is exactly (and only) null
.
To clarify:
PHP will use an explicitly set NULL
value over any default value (in this case, 200
).
So;
// within the function
if($limit !== null) {
//use limit in your PDO
}
This does not convert if $limit == 0
or other type-juggling cases, common to PHP
This above means that if no $limit
value is given then default of 200
is used. If an explicit NULL
value is given, that will be used instead.
Code
Please note this code is for example only and can probably be simplified further to better follow DRY patterns, but I don't know enough about CodeIgniter to do this here and now.
public function __getalldata($tablename,$tablefield=array(),$orderbyfield = 'id',$ascdesc = 'desc',$limit = 200,$type='result')
{
//Query generation according to above parameters
if($limit !== null){
$data = $this->db
->select($tablefield)
->from($tablename)
->order_by($orderbyfield, $ascdesc)
->limit($limit)
->get();
}
else {
$data = $this->db
->select($tablefield)
->from($tablename)
->order_by($orderbyfield, $ascdesc)
->get();
}
return $data->$type();
}
If you can't edit the function
I'm unclear on if you can (or want) to edit the function itself, if you're using Codeigniter, so instead simply refer an automatic value to the function arguments to return every valud row, no matter what (in effect removing the case for limit.
To do this use the PHP Constant PHP_INT_SIZE
or PHP_INT_MAX
which will return exactly that value. Reading this question/answer tells you more about this, but these constants should be self explanatory, as the maximum int values.
If a MySQL LIMIT
exceeds the rows returned, this has no effect, so by setting this to a maximal value, it will always exceed the rows returned and/or the rows usable by the resulting page output.
Therefore:
$var = __getalldata("table",[0=>'columnname'],'id','desc',PHP_INT_MAX,'result');
Will return you every row within the PHP Integer limit of [2,147,483,647] or [9,223,372,036,854,775,807], depending on your system (32bit or 64bit).
And let's face it -- if 2 billion is not enough of a limit, you need to face you have some serious problems with your SQL query ;-)