title: Using mysqli affected rows in object oriented style function - not returning expected result
body: <p>I'm trying to improve my functions include file for a site I'm making. The code below is an extract of the functions include. I'm trying to get get affected_rows to check that the query has been successfully executed but no luck.</p>
  
  <pre><code>&lt;?php
  function connect() {
      $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  
      if ($mysqli-&gt;connect_error) {
          die('Connect Error (' . $mysqli-&gt;connect_errno . ') '
                  . $mysqli-&gt;connect_error);
      }
  
      return $mysqli;
  
  }
  
  function insert($type, $values) {
      $mysqli = connect();
  
      if ( $type == 'newclient' ) {
          $query = "INSERT INTO client_details (first_name, surname, email, password, dob, country, region, postcode, phone_main, phone_mobile, date_registered, regcode) values ( '{$_SESSION['first_name']}', '{$_SESSION['surname']}', '{$_SESSION['confirm_email']}', '$scrambledeggs', '{$_SESSION['dob']}', '{$_SESSION['country']}', '{$_SESSION['region']}', '{$_SESSION['postcode']}', '{$_SESSION['phone_main']}', '{$_SESSION['phone_mobile']}', NOW(), '$verification_hash')";
  
          if ( !$mysqli-&gt;query($query) ) {
          return "Errormessage: $mysqli-&gt;error";  
          }
      }
  }
  </code></pre>
  
  <p>I'm trying to get affected rows in order to confirm the query has run correctly, but my attempts so far haven't worked, this is what I had tried...</p>
  
  <pre><code>if ( !$mysqli-&gt;query($query) ) {
      return "Errormessage: $mysqli-&gt;error";  
  }
  if (($mysqli-&gt;affected_rows) &gt; 0 ) {
      ($_SESSION['success'] = 1);
  }
  </code></pre>