mysql - rewrite queries from deprecated mysql_connect to PDO in PHP -


i rewriting code mysql_connect deprecated below work in pdo cannot work properly. no error showed. have tried could. can me

deprecated mysql_connect

<?php include('config.php'); ?> <?php     if(isset($_post['page'])):     $paged=$_post['page'];     $sql="select * `users` qualify='po' order `uid` desc ";     if($paged>0){            $page_limit=$resultsperpage*($paged-1);            $pagination_sql=" limit  $page_limit, $resultsperpage";            }     else{     $pagination_sql=" limit 0 , $resultsperpage";     }      $result=mysql_query($sql.$pagination_sql);      $num_rows = mysql_num_rows($result);     if($num_rows>0){     while($data=mysql_fetch_array($result)){     $userid=$data['uid'];     $fullname=$data['fullname'];     echo "<li><h3>$userid</h3><p>$fullname<p></li>";     }     }     if($num_rows == $resultsperpage){?>     <li class="loadbutton"><button class="loadmore" data-page="<?php echo  $paged+1 ;?>">load more</button></li>  <?php    }else{     echo "<li class='loadbutton'><h3>no more data</h3></li>";  }   endif;    ?> 

convert pdo

<?php   $resultsperpage=1;  $db = new pdo (     'mysql:host=localhost;dbname=chat;charset=utf8',      'root', // username      '' // password );   ?>  <?php include('pdo.php'); ?> <?php       if(isset($_post['page'])):     $paged=$_post['page'];   $prefix = ""; //loadmore configuarion $resultsperpage=1;  $sql = $db->prepare("select * users qualify=:qualify  order uid desc");         $sql->execute(array(':qualify'=>'po')); if($paged>0){            $page_limit=$resultsperpage*($paged-1);            $pagination_sql=" limit  $page_limit, $resultsperpage";            }     else{     $pagination_sql=" limit 0 , $resultsperpage";     } $result = $db->prepare($sql.$pagination_sql);  $num_rows = $result->rowcount(); if($num_rows>0){   while ($row = $result->fetch()) {  $userid=htmlentities($row['uid'], ent_quotes, "utf-8");   $fullname=htmlentities($row['fullname'], ent_quotes, "utf-8");      echo "<li><h3>$userid</h3><p>$fullname<p></li>";     }     }     if($num_rows == $resultsperpage){?>     <li class="loadbutton"><button class="loadmore" data-page="<?php echo  $paged+1 ;?>">load more</button></li>  <?php    }else{     echo "<li class='loadbutton'><h3>no more data</h3></li>";  }   endif;    ?> 

thank much

your solution here @ http://php.net/manual/en/pdo.setattribute.php , put following code after pdo construct:

$db->setattribute(pdo::attr_errmode,pdo::errmode_exception); 

this won't fix code should show why error occuring , can debug there.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -