Reply to Re: Scrubbing MySQL Values and CSVtoArray()

Your name:

Reply:


Posted by Rik on 08/17/07 02:17

On Fri, 17 Aug 2007 03:56:22 +0200, Sanders Kaufman <bucky@kaufman.net> =
=

wrote:

> Rik wrote:
>> On Fri, 17 Aug 2007 02:46:55 +0200, Sanders Kaufman <bucky@kaufman.ne=
t>
>
>>> 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.

Well, that's OK. Why the hell it's a CSV string instead of the raw data =
is =

another question :P

> 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 fi=
le =

> with a Postgre or file system or whatever else database, to support =

> whatever db I happen to be using at the time.

And that's the point where it might be turned into a CVS string if neede=
d, =

not in your business logic.

>>> 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 =3D array();
>>> $aryRetVal =3D 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 m=
y =

>> 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?

Streams: <http://nl3.php.net/manual/en/wrappers.php>
Stream-functions: <http://nl3.php.net/manual/en/ref.stream.php>
Making your own: =

<http://nl3.php.net/manual/en/function.stream-wrapper-register.php>

Just forgot about the ability to abuse php://memory instead of going =

through the pain of writing a whole wrapper for a single scalar variable=
..

>> 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.

I'm equally amazed PHP still hasn't got simple built-in functionality fo=
r =

this. It's not like CVS is rare...

> 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.

Yup, that's what I was trying to say with the first 'Which shouldn't be =
=

the case' :)

> Still - a nice CSVtoArray() function would be cool.

Indeed.
-- =

Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация