1

Is it possible to fetch all column names that have a pattern? For example, fetch all columns that start with 'allow'. I would like it to only use pure pdo query and not an php array filter.

  $prepare=$database->query("show columns from TABLENAME like 'allow%'");
  $fetched=$prepare->fetchAll();

2 Answers 2

1

Some shared hosts don't let you use the info schema, in those situations you can use show columns, which looks like this.

SHOW COLUMNS FROM `database`.`table` WHERE Field like '%access'
Sign up to request clarification or add additional context in comments.

Comments

0

information_schema.columns holds column and table structure information.

$prepare=$database->query("select column_name from information_schema.columns where table_name='TABLENAME' and column_name like 'allow%'");
$fetched=$prepare->fetchAll(PDO::FETCH_COLUMN);
print_r($fetched);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.