php


MySQL - pass database field through PHP function before returning result


The following code from http://php.morva.net/manual/en/mysqli-stmt.bind-result.php shows a mysqli query being prepared and executed. while ($stmt->fetch()) loop looks like it is generating the result resource. Can I change this to include a call to a function e.g.
while ($stmt->fetch()) {
foreach($row as $key => $val)
{
$c[$key] = performFunction($val);
}
$result[] = $c;
}
Then instead of print_r($result) I would return($result). That way I can dynamically change the value of $val
The original code =
if ($stmt = $mysqli->prepare("SELECT * FROM sample WHERE t2 LIKE ?")) {
$tt2 = '%';
$stmt->bind_param("s", $tt2);
$stmt->execute();
$meta = $stmt->result_metadata();
while ($field = $meta->fetch_field())
{
$params[] = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
while ($stmt->fetch()) {
foreach($row as $key => $val)
{
$c[$key] = $val;
}
$result[] = $c;
}
$stmt->close();
}
$mysqli->close();
print_r($result);
Would this work, how else could I do this?Thanks all...
You could use a UDF (User Defined Function) to process the data on the MySQL side of things before it ever makes it back to PHP.
That's a perfectly valid method, although I suspect your sample implementation code won't quite work. You're probably better off fetching a mysqli_result object, calling fetch_assoc on it, and pushing the resulting associative array onto your result set rather making the associative array yourself.

Related Links

how to make hyperlink to label in zf2
Why is json-rendered output from array_filter different to output from foreach?
Display an image after resizing
Web - Video : bytes range to time
Use another symfony2 project as vendor
Validation - Returning the first error for an AJAX response
How to use HTML tags in Symfony flash message
How to fix MySql Exception Access denied for user 'root'#'localhost' (using password: YES)
create function to accept integer value and function will return id input value is 1 then print 1 else 2 print 1,3 else 3 print 1,3,5 in php
Go On Some Page After Submit
Converting Lat & Long values received from GPS tracker
Codeigniter - send variable within link
Why does the while loop never end?
Is it possible to use the Model Factories with a wrapper service in Laravel?
Find pair of record from one table on the basis of point
Query mysql when reach row then stop? show the queue number

Categories

HOME
protocol-buffers
class
weblogic12c
yahoo-weather-api
mousemove
command-prompt
vsts-build
bing-search
docker-cloud
liferay-7
cypher
swift2
turbojpeg
azure-mobile-services
impala
mailing-list
sharepoint-online
wine
rangy
chromecast
grocery-crud
google-awareness
amazon-elb
orange-api
pinterest
l20n
maven-plugin
office-ui-fabric
bazaar
sharedpreferences
fluent-migrator
restier
tortoisemerge
background-color
hevc
gravity-forms-plugin
php-5.3
code-climate
tilemill
google-play-developer-api
es6-modules
dotcms
objectmapper
knights-tour
image-optimization
jfxtras
nanogallery
mv
django-smart-selects
google-now
swfupload
python-jira
data-uri
vb.net-to-c#
access-denied
minikube
dbcc
vesta
gcal
webalizer
entropy
iptv
pen
libharu
okio
nunit-console
dojo-build
gnucash
highlighting
processor
urbit
vaadin4spring
gwt-syncproxy
gravatar
jsr363
webgrind
enunciate
auto-generate
hmisc
libz
modern.ie
darwin
kotlin-android-extensions
mgwt
nesper
ecos
nidaqmx
network-printers
thruway
profiles
ctp
visual-c++-2005
san
insertion
mongo-jackson-mapper
oscilloscope
gprof
cgrectmake
cakeyframeanimation
series-40
n-queens
memory-pool
background-repeat
motodev-studio
radscheduler
css-friendly
jmenu
3des
ixmldomdocument
projectpier
fuzzy-comparison
rtti
stretchblt
watchpoint

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App