Jump to content

SQL Query and ODBC Connection using PHP Script


jschofield

Recommended Posts

Hello Fellow php scripters,
I have a problem getting my SQL query to work while opening an ODBC connection. The error I get is 'could not decrypt file'...SQL state S1000. Below is my code. Anyone know why its not working? The file I am using is named sj011907.xls. The sheet that is in excel is named 011907. The importlibrary.inc.php script is just a standard logging script. Thanks for all your help. Johnnie

<?php

$inputfile = "C:/SMDIM/Data/sj011907.xls";
$outputfile = "C:/SMDIM/Data/All_Student_Data.csv";
$logfilename = "C:/SMDIM/Logs/All_Student_Log.txt";
include'C:/SMDIM/Translators/importlibrary.inc.php';
//The query
$query = "SELECT * FROM [011907$]";
//The excel driver we need
$connection = odbc_connect('Driver={Microsoft Excel Driver (*.xls)};
DriverId=790;Dbq='.$inputfile.';','','');
$count = 0;
//Execute the query
if(!$dbexec = odbc_exec($connection, $query)) {
wlogdie("Failed to execute the query");
}else{
wlog("Successfully executed the query");
}

//open the file
if(!$outfilefp = fopen($outputfile, "w")) {
wlogdie("Failed to open $outputfile");
}else{
wlog("Opened $outputfile for writing");
}

//read through the file and strip any extra characters from phone numbers
//add English language codes to the end of each line
while  (odbc_fetch_into($dbexec, $row)) {
$temp  = array($row[3],$row[4],$row[9],$row[10],$row[] = "English");
$count++;
writeLine($outfilefp, $row);
}
if($count !== '0') {
wlog("finished the import with a total of $count records");
}else{
wlog("Failed to import data");
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.