Green
Green

Reputation: 30815

Which is better way to manipulate data in DB?

In MySQL there are also functions. For example DAY(), ASCII(), DATEDIFF(), and so on, a lot of function. So it is possible to make complicated queries using these functions. And all computing/manipulation with data will be done still in MySQL by MySQL functions. And I can get the result of my query in PHP already prepared by MySQL as refined as only possible.

But it’s also possible to compute/manipulate data from DB using PHP function. I mean, I retrieve data from DB using as simple SQL query as possible, then get it into an array, fetch that array into variables and only now, using PHP functions, begin necessary manipulations with my data to refine what I need.

So my question which way is better to work with DB? Should I use MySQL’s sever strength as full as only possible to get as ready-to-use data as only possible, or should I use more PHP functions to manipulate raw data from DB?

Upvotes: 1

Views: 1375

Answers (3)

RobinUS2
RobinUS2

Reputation: 955

If you use MySQL (or other non-distributed databases) you might consider doing this in code. This will lighten the load on the database server while webservers are perfectly scalable these days. You only have 1 MySQL server, and can scale up to X webservers.

The best would be to create a helper class that wraps the database native functions.

If you leave the performance issues for what they are, it would always be better to use available functions instead of creating them yourself.

Upvotes: 3

bizzr3
bizzr3

Reputation: 1955

look ta my question Text proccessing via Mysql Query. its better to store simple data into data base as each data one row.then get it to php and proccess them.

Upvotes: -2

Brian Driscoll
Brian Driscoll

Reputation: 19635

Assuming that you'd be executing the same statements against the database in either case, it will always be faster to run your statements directly in MySQL (e.g. functions, stored procedures) than it will be to use any of PHP's MySQL extensions.

Upvotes: 3

Related Questions