Anyone ever experienced this problem.
When i pass a mysql result to the constructor of a class and use that
resultset inside that class the original resultset outside the class gets
affected too. That is not right i think because my result inside my class is
private. Is this a bug? Can someone look at my code below please:
<?php
require_once('includes/connect.php');
class test {
private $_result;
private $_record;
public function __construct($result) {
$this->_result = $result;
}
public function show() {
while($this->_record = mysql_fetch_array($this->_result)) {
echo $this->_record['name'].'<br />';
}
}
}
# usage
# sql statement dat artikels ophaald uit cartal database
$SQL = "SELECT * FROM test_table";
# uitvoeren van dit statement
$RESULT = mysql_query($SQL,$conn);
$t = new test($RESULT);
$t->show();
// mysql_data_seek($RESULT,0);
// this prints out nothing unless i call mysql_data_seek($RESULT,0) before
this whileloop so that means that the pointer of the recordset had moved to
the end because of the while loop in the class itself...that is strange!
while($RECORD = mysql_fetch_array($RESULT)) {
echo $RECORD['name'].'<br />';
}
?> 5 1580
On Aug 27, 10:25 am, "Marcel Molenaar" <afraidofs...@spam.nlwrote:
Anyone ever experienced this problem.
When i pass a mysql result to the constructor of a class and use that
resultset inside that class the original resultset outside the class gets
affected too. That is not right i think because my result inside my class is
private. Is this a bug? Can someone look at my code below please:
<?php
require_once('includes/connect.php');
class test {
private $_result;
private $_record;
public function __construct($result) {
$this->_result = $result;
}
public function show() {
while($this->_record = mysql_fetch_array($this->_result)) {
echo $this->_record['name'].'<br />';
}
}
}
# usage
# sql statement dat artikels ophaald uit cartal database
$SQL = "SELECT * FROM test_table";
# uitvoeren van dit statement
$RESULT = mysql_query($SQL,$conn);
$t = new test($RESULT);
$t->show();
// mysql_data_seek($RESULT,0);
// this prints out nothing unless i call mysql_data_seek($RESULT,0) before
this whileloop so that means that the pointer of the recordset had moved to
the end because of the while loop in the class itself...that is strange!
while($RECORD = mysql_fetch_array($RESULT)) {
echo $RECORD['name'].'<br />';
}
?>
The result is a resource, so there's only one of them to pass around.
It doesn't make a copy of it when you pass it into the class.
On 27.08.2007 16:25 Marcel Molenaar wrote:
Anyone ever experienced this problem.
When i pass a mysql result to the constructor of a class and use that
resultset inside that class the original resultset outside the class gets
affected too. That is not right i think because my result inside my class is
private. Is this a bug?
No, this is the expected behaviour. Resources, like db connections or
result handles are always assigned and passed as pointers, that is,
changing one variable will affect another one if both point to the same
object.
--
gosha bine
makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
"ZeldorBlat" <ze********@gmail.comwrote in message
news:11*********************@y42g2000hsy.googlegro ups.com...
On Aug 27, 10:25 am, "Marcel Molenaar" <afraidofs...@spam.nlwrote:
>Anyone ever experienced this problem.
When i pass a mysql result to the constructor of a class and use that resultset inside that class the original resultset outside the class gets affected too. That is not right i think because my result inside my class is private. Is this a bug? Can someone look at my code below please:
<?php
require_once('includes/connect.php');
class test {
private $_result; private $_record;
public function __construct($result) {
$this->_result = $result;
}
public function show() {
while($this->_record = mysql_fetch_array($this->_result)) {
echo $this->_record['name'].'<br />';
}
}
}
# usage # sql statement dat artikels ophaald uit cartal database $SQL = "SELECT * FROM test_table";
# uitvoeren van dit statement $RESULT = mysql_query($SQL,$conn);
$t = new test($RESULT);
$t->show();
// mysql_data_seek($RESULT,0);
// this prints out nothing unless i call mysql_data_seek($RESULT,0) before this whileloop so that means that the pointer of the recordset had moved to the end because of the while loop in the class itself...that is strange! while($RECORD = mysql_fetch_array($RESULT)) {
echo $RECORD['name'].'<br />';
}
?>
The result is a resource, so there's only one of them to pass around.
It doesn't make a copy of it when you pass it into the class.
Thanks!
But is it possible to copy it into a new temporary resource so the original
result will stay untouched?
Marcel
Marcel Molenaar wrote:
"ZeldorBlat" <ze********@gmail.comwrote in message
news:11*********************@y42g2000hsy.googlegro ups.com...
>On Aug 27, 10:25 am, "Marcel Molenaar" <afraidofs...@spam.nlwrote:
>>Anyone ever experienced this problem.
When i pass a mysql result to the constructor of a class and use that resultset inside that class the original resultset outside the class gets affected too. That is not right i think because my result inside my class is private. Is this a bug? Can someone look at my code below please:
<?php
require_once('includes/connect.php');
class test {
private $_result; private $_record;
public function __construct($result) {
$this->_result = $result;
}
public function show() {
while($this->_record = mysql_fetch_array($this->_result)) {
echo $this->_record['name'].'<br />';
}
}
}
# usage # sql statement dat artikels ophaald uit cartal database $SQL = "SELECT * FROM test_table";
# uitvoeren van dit statement $RESULT = mysql_query($SQL,$conn);
$t = new test($RESULT);
$t->show();
// mysql_data_seek($RESULT,0);
// this prints out nothing unless i call mysql_data_seek($RESULT,0) before this whileloop so that means that the pointer of the recordset had moved to the end because of the while loop in the class itself...that is strange! while($RECORD = mysql_fetch_array($RESULT)) {
echo $RECORD['name'].'<br />';
}
?>
The result is a resource, so there's only one of them to pass around. It doesn't make a copy of it when you pass it into the class.
Thanks!
But is it possible to copy it into a new temporary resource so the original
result will stay untouched?
Marcel
You can make a copy, but since this isn't your actual data, but a
reference to data residing in MySQL, it won't do any good.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:VM******************************@comcast.com. ..
Marcel Molenaar wrote:
>"ZeldorBlat" <ze********@gmail.comwrote in message news:11*********************@y42g2000hsy.googlegr oups.com...
>>On Aug 27, 10:25 am, "Marcel Molenaar" <afraidofs...@spam.nlwrote: Anyone ever experienced this problem.
When i pass a mysql result to the constructor of a class and use that resultset inside that class the original resultset outside the class gets affected too. That is not right i think because my result inside my class is private. Is this a bug? Can someone look at my code below please:
<?php
require_once('includes/connect.php');
class test {
private $_result; private $_record;
public function __construct($result) {
$this->_result = $result;
}
public function show() {
while($this->_record = mysql_fetch_array($this->_result)) {
echo $this->_record['name'].'<br />';
}
}
}
# usage # sql statement dat artikels ophaald uit cartal database $SQL = "SELECT * FROM test_table";
# uitvoeren van dit statement $RESULT = mysql_query($SQL,$conn);
$t = new test($RESULT);
$t->show();
// mysql_data_seek($RESULT,0);
// this prints out nothing unless i call mysql_data_seek($RESULT,0) before this whileloop so that means that the pointer of the recordset had moved to the end because of the while loop in the class itself...that is strange! while($RECORD = mysql_fetch_array($RESULT)) {
echo $RECORD['name'].'<br />';
}
?> The result is a resource, so there's only one of them to pass around. It doesn't make a copy of it when you pass it into the class. Thanks!
But is it possible to copy it into a new temporary resource so the original result will stay untouched?
Marcel
You can make a copy, but since this isn't your actual data, but a
reference to data residing in MySQL, it won't do any good.
--
Thanks for your help! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Hunter |
last post by:
I have a class that uses some extension code I have written and I am
trying to track down some memory leaks, which I presume to be in my
extension code. The class is question is in a python...
|
by: Anon Email |
last post by:
Hi people,
I'm playing around with Bartosz Milewski's code at the moment, and I
got the following strange results upon execution of the code included
further below. Please be aware that I...
|
by: Karahan Celikel |
last post by:
Here are three simple classes:
class A
{
public void DoIt(B b)
{
DoSomething(b);
}
public void DoSomething(B b)
{
|
by: Arnold Schrijver |
last post by:
I wrote a program that draws items to the screen and maintains a set of
Offset values.
There was a bug in the code, because objects were positioned wrongly. While
debugging
I found some peculiar...
|
by: Paul Czubilinski |
last post by:
Hello,
I have a problem with code like this (PHP 5.1.4):
fila A.php:
=======
include(B.php);
class document extends obj {
.........
|
by: M. Posseth |
last post by:
i have 3 forms
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim frm As New Form2
frm.Show(Me)
End Sub...
|
by: senfo |
last post by:
I developed a Windows control in VS 2005 that inherits from the
PictureBox Control that adds the ability to select images in a Windows
application. It is, however, experiencing a strange issue...
|
by: rconradharris |
last post by:
A co-worker of mine came across some interesting behavior in the
Python interpreter today and I'm hoping someone more knowledgeable in
Python internals can explain this to me.
First, we create...
|
by: Marcel Molenaar |
last post by:
Anyone ever experienced this problem.
When i pass a mysql result to the constructor of a class and use that
resultset inside that class the original resultset outside the class gets
affected...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
|
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...
| |