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 wrap element with another element with php
Using PHP as a Backend with Ember.js
Using array from header in another page
How to detect hashed password length? [closed]
Add data to multiple data fields
How to destroy the APC cache in YII
.val() not capturing the textbox value when button is clicked
PHP calling in more than 1 Tweet
PHPExcel - How to apply borders to dynamic range of cells loaded from mysql data
CodeIgniter Active record update not working
Creating MySQL leaderboard
JSON_BIGINT_AS_STRING removed in php 5.5?
Calling a Model Function in View?
PHP Regex: Extracting content from piped curly braces
Merge these array values into a new array?
Compare directory contents to database column in Joomla

Categories

HOME
oracle
mc
weblogic12c
workflow
concurrency
plpgsql
risk-management
initialization
odata
video-streaming
google-search-console
supercollider
gprs
specifications
cocotb
yeoman-generator-angular
alljoyn
parsley.js
vimeo
mpu6050
rest-assured
jqxgrid
scheduled-tasks
hdl
neo4j.rb
websphere-portal
substring
sipp
jstree
introspection
spreadsheetgear
marquee
basic-authentication
objectmapper
series
quickcheck
java-stream
dreamfactory
cups
hidden-markov-models
hypothesis-test
sendinput
django-static-precompiler
xcglogger
password-hash
ilrepack
comm
iptv
android-sharing
word-2016
allegro
thread-exceptions
jpda
visual-studio-monaco
zynq
raw-sockets
cdo.message
deferred-rendering
exists
mathnet
voronoi
wikimedia-commons
stack-smash
decidable
gluon-desktop
netdatacontractserializer
apple
org-babel
componentart
textscan
kefir.js
flow-js
prism-4
sql-processor
dnsjava
window-resize
ecos
nidaqmx
nachos
gpu-programming
flipboard
assetic
xsd2code
boinc
mute
form-for
dynamic-rdlc-generation
mongo-jackson-mapper
handshake
cgrectmake
spark-view-engine
zend-pdf
coordinate
cakeyframeanimation
netstream
gwt-celltable
expression-web
will-paginate
getopts
tablet-pc
git-log
solandra
mongrel
cassini
outlook-2007-addin
tessellation
activestate
autobench
rakudo
community-server

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App