473,770 Members | 6,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing data in Objectified mysql records

Hello,

I am using this very slightly modified function found here:
http://us2.php.net/mysql_fetch_object
to make mySQL rows into objects of type $classname:

// This takes db result rows and makes real objects of $classname type
function &buildObj($resu lt, $classname) {
while($row = mysql_fetch_ass oc($result)) {
if ($row === null) return null;

/* Create the object */
$obj =& new $classname;

/* Explode the array and set the objects's instance data */
foreach($row as $key => $value)
{
$obj->{$key} = $value;
}
$objs[] = $obj;
}
return $objs;
}

This is called by a retrieve: function:

function retrieve($where ) {
echo $query = "SELECT * FROM $this->table WHERE " . join(' AND ',
$where);
$result = mysql_query($qu ery);
$rows =& buildObj($resul t, get_class($this ));
mysql_free_resu lt($result);
return $rows;
}

The problem I am encountering is that if I do this in my script:

$listing = new Listing;
$listings = $listing->retrieve(array ('row > 1') );
foreach ($listing as $aListing) {
$aListing->address='xxxxx xxxxxxxx';
}
foreach ($listing as $aListing) {
print_r($aListi ng);
}

The value in $aListing->address is unchanged.

However if I do this:

$listing = new Listing;
$listings = $listing->retrieve(array ('row > 1') );
foreach ($listing as $aListing) {
$aListing->address='xxxxx xxxxxxxx';
$newArray[] = $aListing;
}
foreach ($newArray as $aListing) {
print_r($aListi ng);
}
I see the update values in $aListing->address .

What gives? Can anyone help me out here?

BTW I also tried removing the reference operator (&) from the whole thing
but it didn't help, I don't know why the author of the sub had used it.

TIA,

jg


Jul 17 '05 #1
1 1620
My error was trying to act on $this when I had passed $obj.

jg
"jerrygarci uh" <de*****@no.spa m.nolaflash.com > wrote in message
news:p4yKc.2819 $fB4.622@lakere ad01...
Hello,

I am using this very slightly modified function found here:
http://us2.php.net/mysql_fetch_object
to make mySQL rows into objects of type $classname:

// This takes db result rows and makes real objects of $classname type
function &buildObj($resu lt, $classname) {
while($row = mysql_fetch_ass oc($result)) {
if ($row === null) return null;

/* Create the object */
$obj =& new $classname;

/* Explode the array and set the objects's instance data */
foreach($row as $key => $value)
{
$obj->{$key} = $value;
}
$objs[] = $obj;
}
return $objs;
}

This is called by a retrieve: function:

function retrieve($where ) {
echo $query = "SELECT * FROM $this->table WHERE " . join(' AND ',
$where);
$result = mysql_query($qu ery);
$rows =& buildObj($resul t, get_class($this ));
mysql_free_resu lt($result);
return $rows;
}

The problem I am encountering is that if I do this in my script:

$listing = new Listing;
$listings = $listing->retrieve(array ('row > 1') );
foreach ($listing as $aListing) {
$aListing->address='xxxxx xxxxxxxx';
}
foreach ($listing as $aListing) {
print_r($aListi ng);
}

The value in $aListing->address is unchanged.

However if I do this:

$listing = new Listing;
$listings = $listing->retrieve(array ('row > 1') );
foreach ($listing as $aListing) {
$aListing->address='xxxxx xxxxxxxx';
$newArray[] = $aListing;
}
foreach ($newArray as $aListing) {
print_r($aListi ng);
}
I see the update values in $aListing->address .

What gives? Can anyone help me out here?

BTW I also tried removing the reference operator (&) from the whole thing
but it didn't help, I don't know why the author of the sub had used it.

TIA,

jg

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3229
by: Jerry Weinstein | last post by:
Hi, I know about stored procedures and that they can speed up data entry via the SQL 'insert ' statement. However, one drawback to this method is that using the stored procedure still requires one to manually and individually enter each and every record to be inserted to the database before the procedure is executed. I want to circumvent this tedium by finding a way to use maybe a VB application that prompts a user for the data to be...
2
7060
by: Alex Hunsley | last post by:
I'm using a mysql monitor under cygwin (on win xp) to do a 'load data infile' to put some data into a mysql database (I'm using the xampp bundle).. My problem is that I have a four line CSV file beign inserted, but only two records actually get inserted: mysql> use master; delete from data; LOAD DATA INFILE 'D:/customJobs/database setup/dbaseFourLines.csv' REPLACE INTO TABLE data FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'...
1
1294
by: Tony W. | last post by:
I have a MySQL question about changing the info in a table: I am using MySQL Server version: 3.23.58 I have a table called sign_region2 and it contains thousands of references to signs and the regions they are in. mysql> desc sign_region2; +-----------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra |
1
3115
by: trt08010 | last post by:
I'm new to MySQL so hopefully this all makes sense. I'm running mysql-3.23.58-14 on Fedora Core 3 and everything installs and comes up correctly using default locations for everything. However, I installed an 800GB RAID5 array in the server and created a new file system on it and I attempted to move the datadir location to the new file system and that's when the problems started. Basically what I did was this - I shut down mysqld and...
3
4726
by: hamvil79 | last post by:
I'm implementig a java web application using MySQL as database. The main function of the application is basically to redistribuite documents. Those documents (PDF, DOC with an average size around 2Mb) are stored in BLOB column. The amount of documents for the first year should not exceed 5/6 Giga, but I cannot make prevision for the next years. Those documents are mainly just accessed (update and delete are not so
2
2074
by: S P Arif Sahari Wibowo | last post by:
Hi! Do you know how to put a form's Access-Visual-Basic-code that will force the form to be inserted, while the user has not type anything in the form, without changing focus, selection, etc.? Here is the story. I have this structure:
12
7597
by: VMI | last post by:
For some reason, the process of retrieving data (about 20 records) from an Access table that has 400K records to a dataTable is taking over 3 mins. to complete. Below is my code to connect to the DB and query the table. The table "audit" primary key is "Line". Another weird thing (but I guess that's another post) is that, while it's doing the dataset Fill, my PC is slowed done substantially. But I don't know why that would happen since...
4
2948
by: Good Man | last post by:
Hi there I have a database with about 20 or so tables, maybe a few thousand rows in each. I am starting to do more complex things with my insertions etc, and I want to start to use transactions, so I imagine I should change some table types in the database from MyISAM to InnoDB. I know that InnoDB tables are a completely different beast than MyISAM in terms of data storage etc... ie: instead of using folders on the server, everything...
7
1859
by: Ming | last post by:
For example, 100,000 records, each record has 10 fields and may belong to one or more categories. How shall I save those records in DB? I think it is a very typical concern for most online shopping mall. Option 1) A table with all 100,000 records, and 10 fields for each record Option 2)
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.