I am connecting to an Excel file from PHP via PDO. When executing a query, Excel returns data, but it defines the first row of results as column names. How do I make Excel return all rows, including the first one, as data?
$sheet = 'Sheet1';
$fileName = '/123.xlsx';
$dbh = new PDO("odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};HDR=NO;Dbq=$fileName;ReadOnly=False;", '', '');
$query = "
SELECT
*
FROM [{$sheet}$]
";
$results = $dbh->query($query)->fetchAll(PDO::FETCH_ASSOC);
PHP8.3 Excel2016 Win 10 x64
xlsxis a ZIP package containing well-defined XML files. While you could read them directly, there are a lot of libraries that simplify this, run on all OSs and don't have bitness issuesHeader=Falseinstead ofHDR=NO. I have no idea if that will work, but I'm going by what I read here. I have my doubts about this, but it can't hurt to try. Did you find any documentation for the Data Source Name, or DSN, in this case? What does it say? Do you have a link?HDR=NOis a part ofExtended Properties="...;HDR=NO;...", not a standalone key. Assuming your provider supports theExtended Properties.