Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Passing information from class
Old 03-30-2008, 03:26 PM Passing information from class
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
Okay Slight question,

I am working on a database class that will handle all information for users on one of my sites. And I would like to pass back to the main php script (not the class) the information from the SELECT query in my class. But with out adding in extra information

Current class return

PHP Code:
$subres $this->query($res);
// echo "<br>";
// echo $subres;
$data mysql_fetch_assoc($subres) or die(mysql_error());
global 
$cache ;
$data3 serialize($data);
$cache var_dump($data3,true);
return 
$data3
and gathering the info
PHP Code:
        $cache explode(",",$cache);
        
$print sprintf("Username = %s <br> Password = %s",$cache[1],$cache[7]);
        
$data2 unserialize($data1);
        
print_r($cache);
        
$ndata unserialize($data3);
        
print_r($ndata); 
If i var_dump/export it passes the info but i am adding extra information that will be unpredictable to remove from the out put. and I tried serialize the info then unserialize the data back again wont work.

Any ideas how to get information from a class?
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
 
Register now for full access!
Old 03-31-2008, 12:57 AM Re: Passing information from class
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
WTF is going on? Why don't you simply return an array or an object which represents a single record from your table and is a result of mysql_fetch_*() ? What are those *serialize() for?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 03-31-2008, 10:01 AM Re: Passing information from class
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
OKay let me try and explain my crazy idiot logic here

I have a class, dbconnect.php that handles all my database queries, All the data gets inputed correctly and the query runs and gets the information.

And I was trying to find a way to get the data from the mysql_fetch_assoc function back to the script out side of the class. And when I try this

PHP Code:
        $subres $this->query($res);
        
$data mysql_fetch_assoc($subres);
        
        return 
$data
All is i get is blank page with no data. but if I echo the $data in the class it will out put what i am looking for, but is still not accessible to the script out side of the class.

Var_export works but creates unanticipated data results. and makes it more dificult to replace the data with spaces or put into an array.
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1

Last edited by amw_drizz; 03-31-2008 at 10:07 AM..
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 04-01-2008, 01:50 AM Re: Passing information from class
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Very strange. Let me show you how I do it and everything works:
PHP Code:
$db = new DB();
$db->setup("localhost""user""pass""dbname");
$sql "select * from table where id > 10";
$objects $db->fetch_objects($sql);
foreach (
$objects as $o) {
   print 
"Name: {$o->name}<br />";

DB class is attached. DB class contains methods to retrieve single value, array of values, single object and array of objects.
Attached Files
File Type: txt DB.class.php.txt (5.9 KB, 6 views)
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 04-02-2008, 09:09 PM Re: Passing information from class
Registered User

Posts: 48
Trades: 0
I still wondering why some people think classes useful.
Isnt this more simple?

PHP Code:
$db db_connect("localhost""user""pass""dbname"); 
$objects arrayfromquery("select * from table where id > 10"); 
foreach (
$objects as $key => $value) { 
   print 
"Name: {$value}<br />"


Last edited by ClaFanN1; 04-02-2008 at 09:14 PM..
ClaFanN1 is offline
Reply With Quote
View Public Profile
 
Old 04-03-2008, 12:19 AM Re: Passing information from class
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Please be so kind to not call things useless only because you don't understand what they are made for.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 04-03-2008, 07:06 AM Re: Passing information from class
Registered User

Posts: 48
Trades: 0
Are we going to start a Einstein-bohr debate here?
Watch your dice, they are about to fall, if you want to always predict the results then just don't throw them, let that job for god

Its pretty clear, for me as long PHP runs on per request classes are completely redundant.

Last edited by ClaFanN1; 04-03-2008 at 07:08 AM..
ClaFanN1 is offline
Reply With Quote
View Public Profile
 
Old 04-03-2008, 07:25 AM Re: Passing information from class
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Its pretty clear, for me as long PHP runs on per request classes are completely redundant.
I could not object stronger as I do now.
If you think about your program before you actually write the code, classes have a monumental role to play.

I do nothing outside of classes, except calling classes methods, and since I took this way, my code became way more clear, re-usable, simpler to maintain and more organized.

The fact that it runs on a per request (fire and forget style) doesn't prevent this.
If you use the singleton design pattern for your classes, the state of your objects stay from calls to calls, and is way more elegant than several global variables.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-03-2008, 11:04 AM Re: Passing information from class
Registered User

Posts: 48
Trades: 0
OK, classes are the best... Happy now?
I can also say Bin Laden's america president too if you want...
ClaFanN1 is offline
Reply With Quote
View Public Profile
 
Old 04-03-2008, 01:00 PM Re: Passing information from class
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
I can also say Bin Laden's america president too if you want...
Do you always react like a spoiled child when someone have another opinion than you ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-03-2008, 01:53 PM Re: Passing information from class
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
My object oriented programming is not that strong, as I am more of a front-end developer, but every large, database driven site or application that I have ever worked in has used classes, not pure logic. It is much more logical, to me, from an organizational sense, to drive large sites with objects.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-03-2008, 02:54 PM Re: Passing information from class
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
Quote:
Originally Posted by ClaFanN1 View Post
Are we going to start a Einstein-bohr debate here?
Watch your dice, they are about to fall, if you want to always predict the results then just don't throw them, let that job for god

Its pretty clear, for me as long PHP runs on per request classes are completely redundant.
Quote:
Originally Posted by ClaFanN1
OK, classes are the best... Happy now?
I can also say Bin Laden's america president too if you want...
IF you dont have anything constructive to my orginal question and are just looking start a flame war then stay out of it please.
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Reply     « Reply to Passing information from class
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.98863 seconds with 13 queries