@@ -64,9 +64,11 @@ public function create( $args, $assoc_args ) {
6464 $ grant_privileges = Utils \get_flag_value ( $ assoc_args , 'grant-privileges ' , false );
6565
6666 // Escape identifiers for SQL
67- $ username_escaped = $ this ->esc_sql_ident ( $ username );
68- $ host_escaped = $ this ->esc_sql_ident ( $ host );
69- $ user_identifier = "{$ username_escaped }@ {$ host_escaped }" ;
67+ $ username_escaped = self ::esc_sql_ident ( $ username );
68+ $ host_escaped = self ::esc_sql_ident ( $ host );
69+ assert ( is_string ( $ username_escaped ) );
70+ assert ( is_string ( $ host_escaped ) );
71+ $ user_identifier = "{$ username_escaped }@ {$ host_escaped }" ;
7072
7173 // Create user
7274 $ create_query = "CREATE USER {$ user_identifier }" ;
@@ -81,8 +83,9 @@ public function create( $args, $assoc_args ) {
8183 // Grant privileges if requested
8284 if ( $ grant_privileges ) {
8385 $ database = DB_NAME ;
84- $ database_escaped = $ this ->esc_sql_ident ( $ database );
85- $ grant_query = "GRANT ALL PRIVILEGES ON {$ database_escaped }.* TO {$ user_identifier }; " ;
86+ $ database_escaped = self ::esc_sql_ident ( $ database );
87+ assert ( is_string ( $ database_escaped ) );
88+ $ grant_query = "GRANT ALL PRIVILEGES ON {$ database_escaped }.* TO {$ user_identifier }; " ;
8689 parent ::run_query ( $ grant_query , $ assoc_args );
8790
8891 // Flush privileges
@@ -106,18 +109,4 @@ private function esc_sql_string( $value ) {
106109 $ value = str_replace ( "' " , "'' " , $ value );
107110 return "' " . $ value . "' " ;
108111 }
109-
110- /**
111- * Escapes (backticks) MySQL identifiers (aka schema object names).
112- *
113- * Note: This duplicates functionality from parent DB_Command::esc_sql_ident()
114- * which is private static and cannot be accessed from child classes.
115- *
116- * @param string $ident A single identifier.
117- * @return string An escaped string.
118- */
119- private function esc_sql_ident ( $ ident ) {
120- // Escape any backticks in the identifier by doubling.
121- return '` ' . str_replace ( '` ' , '`` ' , $ ident ) . '` ' ;
122- }
123112}
0 commit comments