0

I'm trying to write a function that returns an array of column names for a MySQL table.

When I use something like this in HeidiSQL

SELECT COLUMN_NAME FROM information_schema.COLUMNS
WHERE table_schema = 'myDB'
AND TABLE_NAME = 'myTable'

I get exactly what I want. A single column of output showing the column names.

when I took the above code and used it in a PHP program using PDO calls every array value is of the format:

string(xx) "column_name"

I do not want the leading "string(xx)" in front of the column name.

I'm using the pdo function as follows:

fetchAll(PDO::FETCH_COLUMN)

I don't see other PDO fetch options to just give me the column names, without the leading "string(xx)" value.

I could parse the results and strip the leading string(xx) value, but I was wondering if there's an easier/better trick.

Tom Hoffman
  • 115
  • 4

1 Answers1

0

Oh, mental lapse... as I dug deeper into my output array, I was thrown off by my output because I was using var_dump. var_dump prefaces the values with the "string(xx)" value. MySQL isn't the one putting the "string(xx)" prefix.

Live and learn...

Tom Hoffman
  • 115
  • 4