Page 467 - Beginning PHP 5.3
P. 467

Chapter 14: Manipulating MySQL Data with PHP
                                 $sql = “UPDATE “ . TBL_MEMBERS . “ SET
                                           username = :username,
                                           $passwordSql
                                           firstName = :firstName,
                                           lastName = :lastName,
                                           joinDate = :joinDate,
                                           gender = :gender,
                                           favoriteGenre = :favoriteGenre,
                                           emailAddress = :emailAddress,
                                           otherInterests = :otherInterests
                                         WHERE id = :id”;

                                 try {
                                   $st = $conn- > prepare( $sql );
                                   $st- > bindValue( “:id”, $this- > data[“id”], PDO::PARAM_INT );
                                   $st- > bindValue( “:username”, $this- > data[“username”], PDO::PARAM_STR );
                                   if ( $this- > data[“password”] ) $st- > bindValue( “:password”, $this- > data
                             [“password”], PDO::PARAM_STR );
                                   $st- > bindValue( “:firstName”, $this- > data[“firstName”],
                             PDO::PARAM_STR );
                                   $st- > bindValue( “:lastName”, $this- > data[“lastName”], PDO::PARAM_STR );
                                   $st- > bindValue( “:joinDate”, $this- > data[“joinDate”], PDO::PARAM_STR );
                                   $st- > bindValue( “:gender”, $this- > data[“gender”], PDO::PARAM_STR );
                                   $st- > bindValue( “:favoriteGenre”, $this- > data[“favoriteGenre”], PDO::
                             PARAM_STR );
                                   $st- > bindValue( “:emailAddress”, $this- > data[“emailAddress”], PDO::
                             PARAM_STR );
                                   $st- > bindValue( “:otherInterests”, $this- > data[“otherInterests”], PDO::
                             PARAM_STR );
                                   $st- > execute();
                                   parent::disconnect( $conn );
                                 } catch ( PDOException $e ) {
                                   parent::disconnect( $conn );
                                   die( “Query failed: “ . $e- > getMessage() );
                                 }
                               }

                               public function delete() {
                                 $conn = parent::connect();
                                 $sql = “DELETE FROM “ . TBL_MEMBERS . “ WHERE id = :id”;

                                 try {
                                   $st = $conn- > prepare( $sql );
                                   $st- > bindValue( “:id”, $this- > data[“id”], PDO::PARAM_INT );
                                   $st- > execute();
                                   parent::disconnect( $conn );
                                 } catch ( PDOException $e ) {
                                   parent::disconnect( $conn );
                                   die( “Query failed: “ . $e- > getMessage() );
                                 }

                               }





                                                                                                         429





                                                                                                      9/21/09   9:14:12 AM
          c14.indd   429
          c14.indd   429                                                                              9/21/09   9:14:12 AM
   462   463   464   465   466   467   468   469   470   471   472