title: PHP OOP & MySQL
body: <p>I have written a procedural version of a script that will sync an iTunes Library with another drive, in my case a NAS. Chatting with some people at work and they suggested that it might be better, neater and a bit cooler to write in using objects. I like a challenge so I thought yeah I could give that a go. I have been reading around for the past couple of days, trying a few things without a lot of success. I have today been trying to follow the tutorials at;
  <a href="http://buildinternet.com/2009/07/an-introduction-to-object-oriented-php-part-1/" rel="nofollow">http://buildinternet.com/2009/07/an-introduction-to-object-oriented-php-part-1/</a>, <a href="http://buildinternet.com/2009/07/an-introduction-to-object-oriented-php-part-2/" rel="nofollow">http://buildinternet.com/2009/07/an-introduction-to-object-oriented-php-part-2/</a> &amp; <a href="http://buildinternet.com/2009/07/an-introduction-to-object-oriented-php-part-3/" rel="nofollow">http://buildinternet.com/2009/07/an-introduction-to-object-oriented-php-part-3/</a>.</p>
  
  <p>While I find the principals of Classes, objects and methods / functions easy enough, their execution vexes me.</p>
  
  <p>Here is the code I have written to perform a simple SQL SELECT query.</p>
  
  <p>Below is my classFile</p>
  
  <pre><code>    &lt;?php //classFile...
      class myClass { // Part 2 of three part series
  
          //Initiate class variables
          public $server = 'localhost';
          public $user = 'itunes';
          public $passwd = 'itunes';
          public $db = 'itunes_sync';
  
          public $dbCon; //Variable to hold the mysqli connection function
  
          function __construct(){
  
              //$this-&gt;dbCon means reference the variable within this class called mysqli
              $this-&gt;dbCon = mysqli($this-&gt;server, $this-&gt;user, $this-&gt;passwd, $this-&gt;db);
          }
  
          function getStaging(){
              //Peform an SQL SELECT Query
              $myQuery = "SELECT * FROM staging";
  
              /*
               *Define new function variable $resuls
               *$results = $mysqli class variable
               *$mysql class variable has been assigned the function mysqli which has an internal function called query.
               *The second query is not the function variable named above. The query function is passed the $query
               *varibale as its input, in this case the SQL SELECT...
              */
              $results = $this-&gt;mysqli-&gt;query($myQuery);
              $rows = array();
              while($row = $results-&gt;fetch_assoc()){
                   $row[] = $row;
              }
              return $results; //This function returns the results.
          }
      }
  
  
  ?&gt;
  </code></pre>
  
  <p>Below is my PHP file called in the browser.</p>
  
  <pre><code>&lt;?php
  
  //Include class file in index.php file
  require_once('myClass.class.php');
  
  //Initiate a new object of myClass() in variable $myClassObj
  $myClassObj = new myClass();
  
  $data = $myClassObj-&gt;getStaging();
  
  print_r($data);
  
  ?&gt;
  </code></pre>
  
  <p>In the browser I get zero output and I don't see anything when I do a</p>
  
  <pre><code>SELECT * FROM general_log;
  </code></pre>
  
  <p>On the MySQL DB.</p>
  
  <p>Have a look at my in code comments to get an idea of where my head is at. If someone can explain this in simple terms, what's gone wrong and what I need to do to change it,it would really help me out.</p>