1 Reply Latest reply on Nov 3, 2011 9:26 PM by Jason Woodcock

    Searching A MySQL Database...

    Jason Woodcock Level 1

      So, I have a very simple table that has 5 columns:

       

      1. id (primary key)
      2. pid
      3. date
      4. note
      5. user

      And I need to return the results of a search by pid to a datagrid. So, I wrote a class but it doesn't seem to be working...

       

       

      <?php
      class ProjectnotesGetByPID {
      
          var $username = "****";
          var $password = "****";
          var $server = "****";
          var $port = "****";
          var $databasename = "****";
          var $tablename = "****";
      
          var $connection;
      
          public function __construct() {
                $this->connection = mysqli_connect(
                                        $this->server,  
                                        $this->username,  
                                        $this->password, 
                                        $this->databasename,
                                        $this->port
                                    );
      
              $this->throwExceptionOnError($this->connection);
          }
      
          /**
           * Returns the item corresponding to the value specified for the project id.
           */
      
          public function getProject_notesByPID($itemID) {
              
              $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where project_id=?"); 
              $this->throwExceptionOnError();
              
              mysqli_stmt_execute($stmt);
              $this->throwExceptionOnError();
              
              $rows = array();
              
              mysqli_stmt_bind_result($stmt, $row->idproject_notes, $row->project_id, $row->note, $row->date, $row->username);
              
              while (mysqli_stmt_fetch($stmt)) {
                $rows[] = $row;
                $row = new stdClass();
                mysqli_stmt_bind_result($stmt, $row->idproject_notes, $row->project_id, $row->note, $row->date, $row->username);
              }
              
              mysqli_stmt_free_result($stmt);
              mysqli_close($this->connection);
          
              return $rows;
          }
          
          private function throwExceptionOnError($link = null) {
              if($link == null) {
                  $link = $this->connection;
              }
              if(mysqli_error($link)) {
                  $msg = mysqli_errno($link) . ": " . mysqli_error($link);
                  throw new Exception('MySQL Error - '. $msg);
              }        
          }
      }
      
      ?>
      
      

       

      When I add it via the data services wizard, it adds fine. Introspects the proper function. But, when I try to configure the return types through the datawizard, I get an error on line 51:

       

       

      Number of bind variables doesn't match number of fields in prepared statement in C:\wamp\www\ProLinxDesktop\services\ProjectnotesGetByPID.php on line 51

      Of, course, Line 51 is:

       

       

      mysqli_stmt_bind_result($stmt, $row->idproject_notes, $row->project_id, $row->note, $row->date, $row->username);
      

       

      You guys are always helpful, and I've racked my brain, even had a buddy who's better at PHP than me look it over and he said it looks right... So, I'm stumped...