Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2005, 07:30 PM
pyro.699 pyro.699 is offline
 
Join Date: Sep 2005
Location: Fredericton, New Brunswic
Posts: 261
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Damn Classes /; (the php type)

ok, im working on a vb free site and im setting up a code so that inorder to write/read a query i need to only type
PHP Code:
$db->query(); 
now, here is what i hvae built so far!
PHP Code:
class Blizz { var $blizz; }

//set the function
    
$this->connection $resource;
    (
$resource mysql_connect());
 function 
query($query

    
$resource mysql_query($query$this->connection); 
    if (!
$resource
    { 
        
$this->debug_query($query); 
    }

    return 
$resource;
}


$db = new Blizz($dbhost$dbuser$dbpass$dbname); 
ok,
PHP Code:
$dbhost
$dbuser
$dbpass
$dbname 
are all defined above... in the part of the sript that you can't handle!

why isent this working? ill give you my current error:
Quote:
Originally Posted by PHP 5.0.4
Fatal error: Using $this when not in object context in C:\apachefriends\xampp\htdocs\blizz\connect.php on line 35
i dont know if this matters, but line #35 is
Quote:
Originally Posted by Notepad ++
$this->connection = $resource;
anyways, i would ask AJ but, i feel like ive bugged him enough ^^;

Ty in advance
~Cody Woolaver
Reply With Quote
  #2  
Old 12-05-2005, 07:40 PM
Guest190829
Guest
 
Posts: n/a
Default

$this should only be used inside methods AFAIK...

*I'm still very new to OOP*
Reply With Quote
  #3  
Old 12-05-2005, 07:43 PM
pyro.699 pyro.699 is offline
 
Join Date: Sep 2005
Location: Fredericton, New Brunswic
Posts: 261
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Im new aswell ^^

umm, so, where what should i put it inside of?
Reply With Quote
  #4  
Old 12-05-2005, 08:02 PM
Guest190829
Guest
 
Posts: n/a
Default

Well that function isn't even in your class, you're defining a class with no methods in it. I don't know if the below will work as I haven't tested it....nor am I an OOP guru, as I am still learning myself.
PHP Code:
var $resource =mysql_connect();

class 
Blizz 

//set the function
    
 
function query($query

    
$this->connection $resource;
    
$this->resource mysql_query($query$this->connection); 
    if (!
$this->resource
    { 
        
$this->debug_query($query); 
    }

    return 
$this->resource;
}


$db = new Blizz;
$query $db->query("QUERY"); 
And also what do you mean by a vb free site?
Reply With Quote
  #5  
Old 12-05-2005, 08:09 PM
pyro.699 pyro.699 is offline
 
Join Date: Sep 2005
Location: Fredericton, New Brunswic
Posts: 261
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Update of code:
PHP Code:
class Blizz { var $blizz;
         var 
$resource mysql_connect(); }

//set the function
    
$this->connection $resource;
    (
$resource mysql_connect());
 function 
query($query

    
$resource mysql_query($query$this->connection); 
    if (!
$resource
    { 
        
$this->debug_query($query); 
    }

    return 
$resource;
}


//Connect
$db = new Blizz($dbhost$dbuser$dbpass$dbname); 
Quote:
Originally Posted by PHP 5.0.4
Parse error: parse error, expecting `','' or `';'' in C:\apachefriends\xampp\htdocs\blizz\connect.php on line 34
Line 34
Quote:
Originally Posted by Notepad ++
var $resource = mysql_connect(); }
Reply With Quote
  #6  
Old 12-05-2005, 08:12 PM
Guest190829
Guest
 
Posts: n/a
Default

Your closing the class before defining any methods, you have to wrap the closing bracket "}" at the end of all you methods.
Reply With Quote
  #7  
Old 12-05-2005, 08:27 PM
pyro.699 pyro.699 is offline
 
Join Date: Sep 2005
Location: Fredericton, New Brunswic
Posts: 261
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yeah, i had a feeling that was an answer
Updated Script
PHP Code:
class Blizz { var $blizz;
            var 
$resource mysql_connect();

//set the function
        
$this->connection $resource;
        (
$resource mysql_connect());
    function 
query($query
    { 
        
$resource mysql_query($query$this->connection); 
        if (!
$resource
        { 
            
$this->debug_query($query); 
        }

        return 
$resource;
    }
}

//Connect
$db = new Blizz($dbhost$dbuser$dbpass$dbname); 
Quote:
Originally Posted by PHP 5.0.4
Parse error: parse error, expecting `','' or `';'' in C:\apachefriends\xampp\htdocs\php_testing\blizz\co nnect.php on line 28
Line 28:
Quote:
Originally Posted by Notepad ++
var $resource = mysql_connect();
Reply With Quote
  #8  
Old 12-05-2005, 09:14 PM
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
Location: AnimationTalk.com
Posts: 2,367
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you can not run a function or set a var when initialzing it, except for setting it as an array. if you want to set that var as mysql_connect create a constructor function at the beginning of your class.
Reply With Quote
  #9  
Old 12-05-2005, 09:20 PM
The Geek's Avatar
The Geek The Geek is offline
 
Join Date: Sep 2003
Location: Behind you
Posts: 2,779
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just to build on AN-nets excellent pointer:

PHP Code:
class myclass
{
 
var 
myvariable;
 
function 
myclass($var)
{
//your constructor is a function with the same name as your class
$this->myvariable $var;
}

HTH's
Reply With Quote
  #10  
Old 12-05-2005, 09:26 PM
pyro.699 pyro.699 is offline
 
Join Date: Sep 2005
Location: Fredericton, New Brunswic
Posts: 261
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

so, after that, is there anyhting else i need to do? or did i have a whole bunch of shit in mine that wsent neded?

----
ok, scrap what i just said

i am completely lost, can you guys amke me an example? that fully works!

i want to type
PHP Code:
$db->blizz->query("QUERY"); 
and for that query to be ran

you should see all the backup files ive made for this project.. lol.. ig to about 20... and none of em work! i just need this made, idc how much space it takes! i really need this it will save me a lot of time!
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 03:23 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04168 seconds
  • Memory Usage 2,272KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (7)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete