PHP Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

PHP Code

Post by quadoc »

I've a quick question. Suppose I've the following code:

select something from table1

value1 = row["col1"]

then I do

Insert into table1 (col1) value (newvalue)

and then I do

value2 = row["col1"]

Is the value2 still equals to value1 or different?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

should be the same.. but not quite sure what your getting at..

perhaps try it for yourself :wink:
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Jcart wrote:should be the same.. but not quite sure what your getting at..

perhaps try it for yourself :wink:
I think he is just assigning to two different variables and not fetching the data from the DB between assignments.
Now, I am getting a doubt, when a resource like $result is returned, it holds the data is not it...it does not go to database again...is it? :roll:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

raghavan20 wrote:
Jcart wrote:should be the same.. but not quite sure what your getting at..

perhaps try it for yourself :wink:
I think he is just assigning to two different variables and not fetching the data from the DB between assignments.
Now, I am getting a doubt, when a resource like $result is returned, it holds the data is not it...it does not go to database again...is it? :roll:
Took me about 5 times to read that for some reason..

quadoc: I believe you need to elaborate furthur.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

$row will contain a copy of the data from the result resource, which will contain a copy from the database, note: copy - not a direct reference. So aslong as you don't update $row after running the INSERT, it will be the same as it was previous to the INSERT.
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

I was trying to see if the value in $row is changing after doing the insert. Thanks guys!
Post Reply