title: PHP: Translating MySQL to Postgresql
body: <p>I need to translate the following MySQL sentences in PHP to Postgresql</p>
  
  <p>Config.php File</p>
  
  <p>MySQL</p>
  
  <pre><code>$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
  </code></pre>
  
  <p>I tried: (Postgresql)</p>
  
  <pre><code>$db = pg_connect($db_host, $db_username, $db_password, $db_name);
  </code></pre>
  
  <p>MySQL:</p>
  
  <pre><code>$get_total_rows = 0;
  $results = $mysqli-&gt;query("SELECT COUNT(*) FROM menu");
  
  if($results){
  $get_total_rows = $results-&gt;fetch_row(); 
  }
  //break total records into pages
  $total_groups= ceil($get_total_rows[0]/$items_per_group);
  </code></pre>
  
  <p>I tried: (Postgresql) I don't know if I need really to change anything, I just change the name of my variable since it is different in my config.php file</p>
  
  <pre><code>$get_total_rows = 0;
  $results = $db-&gt;query("SELECT COUNT(*) FROM menu");
  
  if($results){
  $get_total_rows = $results-&gt;fetch_row(); 
  }
  //break total records into pages
  $total_groups= ceil($get_total_rows[0]/$items_per_group);
  </code></pre>
  
  <p>MySQL</p>
  
  <pre><code>if($_POST)
  {
  //sanitize post value
  $group_number = filter_var($_POST["group_no"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
  
  //throw HTTP error if group number is not valid
  if(!is_numeric($group_number)){
      header('HTTP/1.1 500 Invalid number!');
      exit();
  }
  
  //get current starting point of records
  $position = ($group_number * $items_per_group);
  
  
  //Limit our results within a specified range. 
  $results = $mysqli-&gt;prepare("SELECT id, name, message FROM paginate ORDER BY id ASC LIMIT $position, $items_per_group");
  $results-&gt;execute(); //Execute prepared Query
  $results-&gt;bind_result($id, $name, $message); //bind variables to prepared statement
  
  
  echo '&lt;ul class="page_result"&gt;';
  while($results-&gt;fetch()){ //fetch values
      echo '&lt;li id="item_'.$id.'"&gt;&lt;span class="page_name"&gt;'.$id.') '.$name.'&lt;/span&gt;&lt;span class="page_message"&gt;'.$message.'&lt;/span&gt;&lt;/li&gt;';  
  }
  echo '&lt;/ul&gt;';
  
  $mysqli-&gt;close();
  }
  </code></pre>
  
  <p>Have not idea how to put this into Postgresql</p>
  
  <p>Thank you so much</p>