|
Posted by Sanders Kaufman on 08/17/07 01:56
Rik wrote:
> On Fri, 17 Aug 2007 02:46:55 +0200, Sanders Kaufman <bucky@kaufman.net>
>> For architectural reasons, I can't do the scrubbing before the
>> function is called, but instead have to do it when it comes to me as
>> this csv SLOB.
>
> Which shouldn't be the case...
Should, shmould. In this case, I absolutely must keep the business
logic separate from the database logic.
I have a database.php file that does *all* of the database work, and
then a base class that does the business logic. But if I have to put
the mysql-specific scrubbing function in the business logic base class -
it defeats the purpose of putting ALL of the database work in database.php.
The idea is that I can just replace the mysql-specific database.php file
with a Postgre or file system or whatever else database, to support
whatever db I happen to be using at the time.
>> My First Question:
>> Can I run the real escape function on $csvValues as a whole, to
>> successfully scrub each parameter - or will I experience undesirable
>> results that way?
>
> If there are strings in it: yes, you'll have undesired results.
I figured - but I had to ask.
>> My Second Question:
>> I can convert an array to csv pretty easily, but going the other way
>> screws me up (because of quoted commas). So, my "architectural
>> reasons" (for this and some other stuff, too) would evaporate if
>> someone could help me write a function like this:
>>
>> function CSVtoArray($sCSV) {
>> $aryRetVal = array();
>> $aryRetVal = foo($sCSV);
>> return $aryRetVal;
>> }
>
>
> Well, there's one in the making or something:
> <http://nl3.php.net/manual/en/function.str-getcsv.php>, it's not in my
> PHP though.
>
> You could define a stream to a variable to get fgetcsv() to work for
> you, might be some overkill.
"Define a stream"? Wassat?
>
> In <http://www.php.net/manual/en/function.split.php> there are some
> efforts to get it right, which one you choose depends on the exact needs.
Wow. This is a *much* bigger deal than I thought.
Fortunately, it looks like I found a fix - by just structuring my code
better.
I was trying to convert an array into a csv, pass it to another
function, and then break it back out into an array. Too many
unnecessary levels of abstraction pretty much guarantees failure, don't it?
My problem solves itself if I just keep it as an array until
*immediately* before composing my sql statement - and THEN scrub the
elements as I do so.
Still - a nice CSCtoArray() function would be cool.
Navigation:
[Reply to this message]
|