Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL SQL_CALC_FOUND_ROWS & FOUND_ROWS() #29

Open
PhantomArt opened this issue Apr 12, 2018 · 3 comments
Open

MySQL SQL_CALC_FOUND_ROWS & FOUND_ROWS() #29

PhantomArt opened this issue Apr 12, 2018 · 3 comments
Assignees

Comments

@PhantomArt
Copy link

PhantomArt commented Apr 12, 2018

How to implement?
Some ideas?

@oscarotero
Copy link
Owner

This is not implemented currently, but it's a good thing to have.
Meanwhile, you can execute the query by yourself:

$statement = $simpleCrud->execute('SELECT SQL_CALC_FOUND_ROWS ...');

@oscarotero oscarotero self-assigned this Apr 12, 2018
oscarotero added a commit that referenced this issue Apr 14, 2018
@oscarotero
Copy link
Owner

Hi. I've implemented this. Now, you can use SQL_CALC_FOUND_ROWS passing true as the second argument of the limit function. For example:

$result = $db->items->select()
    ->limit(50, true) // <-- The second argument "true" use this option
    ->run();

$total = $result->getTotal(); //Returns the result of FOUND_ROWS();

Can you test whether it works propertly?
Do you know if there's a alternative to sqlite? After a quick search, seems like the only way to
emulate it is performing a second query with a SELECT COUNT(*).

@PhantomArt
Copy link
Author

Apparently, this is the only way out. But this is bad, because between the SELECT * and SELECT COUNT(*) calls a string can be inserted that will affect the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants