RE: [PHP] ODBC text file connection problem
| From: | Ethan Nelson | Date: | Tue, 10 Sep 2002 19:13:39 +0000 |
| Subject: | RE: [PHP] ODBC text file connection problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-115878@lists.php.net to get a copy of this message | ||
I know that the connection works because the following command ODBC_tables into which I feed my
connection accurately searches the connection and returns an array with some table information.
[snip]
// ODBC commands to explore connection:
$result = odbc_tables($odbc);
odbc_fetch_into($result,$row);
print_r($row);
// I get the following output to the screen:
Array ( [0] => ***:\***\***\*** [1] => [2] => inputfile.txt [3] => TABLE [4] => )
[/snip]
inputfile.txt in row 2 is the file I want to select from.
Just for kicks, I added the "OR DIE" and got nothing. I'm pretty sure that I have
created a valid ODBC system resource and that my ODBC_connect command succesfully creates a bridge
to my materials. Its just that I can't execute commands beyond the odbc_tables without getting
this big nasty error:
[snip]
$result = odbc_exec($odbc,"SELECT * FROM inputfile.txt");
[/snip]
Warning: SQL error: [Microsoft][ODBC Text Driver] The Microsoft Jet database engine \
cannot open the file '(unknown)'. It is already opened exclusively by another user, \
or you need permission to view its data., SQL state S1000 in SQLExecDirect in \
***:\***\***\***\basecsv2.html on line 53
-Ethan
-----Original Message-----
From: Jay Blanchard [mailto:jay.blanchard@niicommunications.com]
Sent: Tuesday, September 10, 2002 12:03 PM
To: Ethan Nelson; php-general@lists.php.net
Subject: RE: [PHP] ODBC text file connection problem
[snip]
As you can see, If I'm going to preserve the double quotes in the third column, I would have to
come up with a script that would deal with escaped characters.
I was hoping that I could just establish an ODBC connection to the text file, which it appears that
I can, and then select stuff from it. Microsoft's documentation that I could find states that
their text driver doesn't support create/drop table, insert, or update commands (obviously),
but it doesn't mention SELECT as being off limits...
[/snip]
The quotes should not be a problem as you could use addslashes() to escape them. On your connection
you say that it does not return an error;
$odbc =3D odbc_connect("***input","",""); // This appears to work as
no = errors are reported
But you're not testing for errors
$odbc =3D odbc_connect("***input","","") OR die("There is an
error connecting to the CSV file.");
Make sure that you trap every potential error.
Jay
*****************************************************
* Texas PHP Developers Conf Spring 2003 *
* T Bar M Resort & Conference Center *
* New Braunfels, Texas *
* Contact jay.blanchard@niicommunications.com *
* *
* Want to present a paper or workshop? Contact now! *
*****************************************************