Reputation: 739
Is it possible to perform a specific PHP function on data that is being returned by a database query, at the very moment this query is still running?
Let's say we are in some class and we have the following pseudo SQL which should return a couple of rows:
$results = $this->db->query("SELECT PHP_function(column), column 2 FROM table")->fetchAll(PDO::FETCH_ASSOC);
PHP_function
could be json_decode
for example.
Or is this not possible and would it require an additional loop on the results in order to do such a thing?
Upvotes: 0
Views: 86
Reputation: 632
As i know it's not possible to achieve php manipulation while query running , you need to take result and then loop aur use predefined function from
Upvotes: 0
Reputation: 546
Where's the problem with this?
<?php
foreach($results as $key=>$res){
$results[$key]['column'] = PHP_function($res['column']);
}
Beside that MySQL has some useful functions included already, so maybe that one you need is usable right in the query
Upvotes: 0
Reputation: 157828
A manual page for the very function you're using contains an example
Upvotes: 2
Reputation: 57306
No, this is not possible. SQL engine (mysql or any other) is a separate application. PHP can communicate with it, send queries and receive data. Depending on what you want to do in that custom function, you may be able to write a custom function in mysql to do the same thing.
Have a look at create function
documentation for info on how to do that.
Upvotes: 0