title: Using PDO queries in place of mysql i.e deprecated
body: <p>As we all know Mysql has been removed in php v7.0 i am trying to use pdo for fetching data (server side) using datatables using the following example but its in mysql need it in pdo:
  <strong>CODE:</strong></p>
  
  <p>COLUMNS:</p>
  
  <pre><code>/* Array of database columns which should be read and sent back to DataTables. Use a space where
   * you want to insert a non-database field (for example a counter or static image)
   */
  $aColumns = array( 'first_name', 'last_name', 'position', 'office', 'salary' );
  
  /* Indexed column (used for fast and accurate table cardinality) */
  $sIndexColumn = "id";
  
  /* DB table to use */
  $sTable = "datatables_demo";
  </code></pre>
  
  <p>Creating PDO CONNECTION:</p>
  
  <pre><code>$db_host = "localhost";
  $db_name = "sadad";
  $db_user = "root";
  $db_pass = "root";
  
  try{
      $db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
      $db_con-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }
  catch(PDOException $e){
      echo $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>THE FOLLOWING CODE:</p>
  
  <pre><code>$sLimit = "";
  if ( isset( $_GET['iDisplayStart'] ) &amp;&amp; $_GET['iDisplayLength'] != '-1' )
  {
      $sLimit = "LIMIT ".$db_con-&gt;quote( $_GET['iDisplayStart'] ).", ".
          $db_con-&gt;quote( $_GET['iDisplayLength'] );
  }
  
  
  /*
   * Ordering
   */
  if ( isset( $_GET['iSortCol_0'] ) )
  {
      $sOrder = "ORDER BY  ";
      for ( $i=0 ; $i&lt;intval( $_GET['iSortingCols'] ) ; $i++ )
      {
          if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
          {
              $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
                  ".$db_con-&gt;quote( $_GET['sSortDir_'.$i] ) .", ";
          }
      }
  
      $sOrder = substr_replace( $sOrder, "", -2 );
      if ( $sOrder == "ORDER BY" )
      {
          $sOrder = "";
      }
  }
  
  
  /* 
   * Filtering
   * NOTE this does not match the built-in DataTables filtering which does it
   * word by word on any field. It's possible to do here, but concerned about efficiency
   * on very large tables, and MySQL's regex functionality is very limited
   */
  $sWhere = "";
  if ( $_GET['sSearch'] != "" )
  {
      $sWhere = "WHERE (";
      for ( $i=0 ; $i&lt;count($aColumns) ; $i++ )
      {
          $sWhere .= $aColumns[$i]." LIKE '%".$db_con-&gt;quote( $_GET['sSearch'] )."%' OR ";
      }
      $sWhere = substr_replace( $sWhere, "", -3 );
      $sWhere .= ')';
  }
  
  /* Individual column filtering */
  for ( $i=0 ; $i&lt;count($aColumns) ; $i++ )
  {
      if ( $_GET['bSearchable_'.$i] == "true" &amp;&amp; $_GET['sSearch_'.$i] != '' )
      {
          if ( $sWhere == "" )
          {
              $sWhere = "WHERE ";
          }
          else
          {
              $sWhere .= " AND ";
          }
          $sWhere .= $aColumns[$i]." LIKE '%".$db_con-&gt;quote($_GET['sSearch_'.$i])."%' ";
      }
  }
  $my = str_replace(" , ", " ", implode(", ", $aColumns));
  
  /*
   * SQL queries
   * Get data to display
   */
  $sQuery = $db_con-&gt;query("SELECT {$my} FROM   {$sTable} {$sWhere} {$sOrder} {$sLimit}")-&gt;fetchAll(); 
  //$rResult = ( $sQuery );
  
  /* Data set length after filtering */
  $sQuery = "
      SELECT FOUND_ROWS()
  ";
  //$rResultFilterTotal = $sQuery;
  $aResultFilterTotal = $sQuery;
  $iFilteredTotal = $aResultFilterTotal[0];
  
  /* Total data set length */
  $sQuery = "
      SELECT COUNT(".$sIndexColumn.")
      FROM   $sTable
  ";
  $rResultTotal = $db_con-&gt;query( $sQuery ) or die(mysql_error());
  $aResultTotal = $rResultTotal-&gt;fetchAll();
  $iTotal = $aResultTotal[0];
  
  
  /*
   * Output
   */
  $output = array(
      "sEcho" =&gt; intval($_GET['sEcho']),
      "iTotalRecords" =&gt; $iTotal,
      "iTotalDisplayRecords" =&gt; $iFilteredTotal,
      "aaData" =&gt; array()
  );
  
  while ( $aRow = $rResult-&gt;fetchAll() )
  {
      $row = array();
      for ( $i=0 ; $i&lt;count($aColumns) ; $i++ )
      {
          if ( $aColumns[$i] == "version" )
          {
              /* Special output formatting for 'version' column */
              $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
          }
          else if ( $aColumns[$i] != ' ' )
          {
              /* General output */
              $row[] = $aRow[ $aColumns[$i] ];
          }
      }
      $output['aaData'][] = $row;
  }
  
  echo json_encode( $output );
  </code></pre>
  
  <p><strong>ERROR:</strong>
  but i am getting the error ,i am unaware what to change in the above ,kind of getting started in pdo,<strong>an updated answer with code would be appreciated</strong>:</p>
  
  <p><strong>UPDATED THE CODE NOW RECEIVING FOLLOWING ERROR</strong></p>
  
  <pre><code>[28-Aug-2018 16:58:39 UTC] PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''asc' LIMIT '0', '50'' at line 2' in C:\MAMP\htdocs\backend\my.php:131
  Stack trace:
  #0 C:\MAMP\htdocs\backend\my.php(131): PDO-&gt;query('SELECT first_na...')
  #1 {main}
    thrown in C:\MAMP\htdocs\backend\my.php on line 131
  **ERROR:**
  </code></pre>