@@ -80,4 +80,55 @@ public function addNewUser($name, $age, $job) : void {
8080 error_log ("Query failed: " . $ e ->getMessage (), 3 , '../../logs/error.log ' );
8181 }
8282 }
83+
84+ public function editUserName ($ id , $ newName ) : void {
85+ try {
86+ $ query = "UPDATE user SET name = ? WHERE id = ? " ;
87+
88+ if ($ this ->conn === null ) {
89+ throw new Exception ("Database connection is null. " );
90+ }
91+
92+ $ stmt = $ this ->conn ->prepare ($ query );
93+ $ stmt ->bindParam (1 , $ newName , PDO ::PARAM_STR );
94+ $ stmt ->bindParam (2 , $ id , PDO ::PARAM_INT );
95+ $ stmt ->execute ();
96+ } catch (PDOException $ e ) {
97+ error_log ("Query failed: " . $ e ->getMessage (), 3 , '../../logs/error.log ' );
98+ }
99+ }
100+
101+ public function editUserAge ($ id , $ newAge ) : void {
102+ try {
103+ $ query = "UPDATE user SET age = ? WHERE id = ? " ;
104+
105+ if ($ this ->conn === null ) {
106+ throw new Exception ("Database connection is null. " );
107+ }
108+
109+ $ stmt = $ this ->conn ->prepare ($ query );
110+ $ stmt ->bindParam (1 , $ newAge , PDO ::PARAM_STR );
111+ $ stmt ->bindParam (2 , $ id , PDO ::PARAM_INT );
112+ $ stmt ->execute ();
113+ } catch (PDOException $ e ) {
114+ error_log ("Query failed: " . $ e ->getMessage (), 3 , '../../logs/error.log ' );
115+ }
116+ }
117+
118+ public function editUserJob ($ id , $ newJob ) : void {
119+ try {
120+ $ query = "UPDATE user SET job = ? WHERE id = ? " ;
121+
122+ if ($ this ->conn === null ) {
123+ throw new Exception ("Database connection is null. " );
124+ }
125+
126+ $ stmt = $ this ->conn ->prepare ($ query );
127+ $ stmt ->bindParam (1 , $ newJob , PDO ::PARAM_STR );
128+ $ stmt ->bindParam (2 , $ id , PDO ::PARAM_INT );
129+ $ stmt ->execute ();
130+ } catch (PDOException $ e ) {
131+ error_log ("Query failed: " . $ e ->getMessage (), 3 , '../../logs/error.log ' );
132+ }
133+ }
83134}
0 commit comments