John Davidson

java - declaring new enum type php


I'm new to PHP and I'm working on Symfony 4 project

I've made a Java project using an Enum Class called role

public class Role {
public enum RoleEnum {
Admin, SuperAdmin, Etudiant, Entreprise } private Short id;
private RoleEnum name;

public Role(Short id, RoleEnum name) { = id; = name ;

and in my user I made it like this

public abstract class User {

private Long id;
private String nom;
private String email;
private String mdp;
private String tel;
private String photo;
private Role role;
private Boolean etatCompte;

and I've made a relation between the two tables in MySQL

and I created this method in Java too

   public Role getRoleByName(RoleEnum input) {

Statement stm;
try {
stm = cnx.createStatement();

String query = "SELECT id from role Where name='" +input+"'";
ResultSet rst = stm.executeQuery(query);

while ( {
Short id = rst.getShort("id");
return new Role(id, input);
} catch (SQLException ex) {
Logger.getLogger(ServiceEtudiant.class.getName()).log(Level.SEVERE, null, ex);

return null;

and when I'm adding values to the table for example to add "admin" to the role I do it like this

        Role role = s.getRoleByName(Role.RoleEnum.Admin);

can anyone help me or guide how to do it the sameway in my symfony project?

My Answer:
"SELECT * FROM Role WHERE name = '" + + "'";__ ResultSet rs = stm.executeQuery(query);__ if ( {_ return new Role(rs.getShort("id"), RoleEnum.valueOf(rs.getString("name")));_ } else {_ return null;_ }_ } catch (SQLException e) {_ e.printStackTrace();_ return null;_ }_}"

Rate this post

3 of 5 based on 8373 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us