samedi 23 janvier 2021

SQL returns syntax error from laravel raw

I'm trying to make a raw sql request to get all possible status from an enum column :

    public static function getPossibleStatuses(){
        $type = DB::select(DB::raw('show columns from defi_user where field = "category";' ))[0]->Type;
        preg_match('/^enum\((.*)\)$/', $type, $matches);
        $values = array();
        foreach(explode(',', $matches[1]) as $value){
            $values[] = trim($value, "'");
        }
        return $values;
    }

I'm getting this weird syntax error :

Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1 near "show": syntax error (SQL: show columns from defi_user where field = "category";)

Although i copied the query in every syntax checker I know and they all say it's perfectly valid.

What am I missing ? Thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire