php - QL_CALC_FOUND_ROWS pdo? -


i'm trying convert script basic sql pdo. i'm not @ it, have come far pdo returns rows in database (limit 12) can make 2 statements 1 without limit , 1 limit. in sql there, uses ql_calc_found_rows think, returns total rows, , limit rows, query faster.

how can pdo ?

code:

<? // normal sql $result = mysql_query('select sql_calc_found_rows * photos order id asc limit 12'); $row_object = mysql_query('select found_rows() rowcount'); $row_object = mysql_fetch_object($row_object); $actual_row_count = $row_object->rowcount;  // pdo  $result = $pdo->prepare('select * photos order id asc limit 12'); $result->execute(); $totalrows = $result->rowcount();  ?> 

edit: tried things won't work:

$result = $pdo->prepare('select sql_calc_found_rows * photos order id asc limit 12'); $result->execute();  $resultall = $pdo->prepare('select found_rows() rowcount'); $resultall->execute(); $resultall->fetch(pdo::fetch_obj); $actual_row_count = $resultall->rowcount; 

edit2: still no success..

    $result = $pdo->query('select sql_calc_found_rows * photos order id asc limit 12'); $resultall = $pdo->query('select found_rows() rowcount'); $resultall->fetch(pdo::fetch_obj); $actual_row_count = $resultall->rowcount;  print_r($actual_row_count); echo $actual_row_count; 

doesn't echo anything.

credits go explosion pills here...

when you're not feeding query external input, don't have prepare statement:

$result = $pdo->query("select sql_calc_found_rows * photos order id asc limit 12"); 

this should work!


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -