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

Posts: 301
Name: Jon
Location: New York
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
Php 5.2 Mysql 4.1 IIS 6 Win2k3 Server && PHP 5.2 MySQL 4.1 Apache 2.2 (separate machine of course)
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
When You Register, These Ads Go Away!
     
Old 03-31-2008, 12:57 AM Re: Passing information from class
mtishetsky's Avatar
Super Spam Talker

Posts: 880
Location: Volendam, Netherlands
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?
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: 301
Name: Jon
Location: New York
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
Php 5.2 Mysql 4.1 IIS 6 Win2k3 Server && PHP 5.2 MySQL 4.1 Apache 2.2 (separate machine of course)

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
Super Spam Talker

Posts: 880
Location: Volendam, Netherlands
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)
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
Experienced Talker

Posts: 48
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
Super Spam Talker

Posts: 880
Location: Volendam, Netherlands
Please be so kind to not call things useless only because you don't understand what they are made for.
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
Experienced Talker

Posts: 48
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
Fetchez la vache!

Posts: 1,855
Name: Thierry
Location: In the void
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.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-03-2008, 11:04 AM Re: Passing information from class
Experienced Talker

Posts: 48
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
Fetchez la vache!

Posts: 1,855
Name: Thierry
Location: In the void
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 ?
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 04-03-2008, 01:53 PM Re: Passing information from class
wayfarer07's Avatar
Will Work for Talkupation

Posts: 577
Name: Abel Mohler
Location: Asheville, North Carolina USA
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.
__________________
Go FREELANCE <=====||=====> Hire Me
wayfarer07 is online now
Reply With Quote
View Public Profile
 
Old 04-03-2008, 02:54 PM Re: Passing information from class
amw_drizz's Avatar
Ultra Talker

Posts: 301
Name: Jon
Location: New York
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
Php 5.2 Mysql 4.1 IIS 6 Win2k3 Server && PHP 5.2 MySQL 4.1 Apache 2.2 (separate machine of course)
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Reply     « Reply to Passing information from class
 

Thread Tools

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

vB 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.20084 seconds with 14 queries