vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Damn Classes /; (the php type) (https://vborg.vbsupport.ru/showthread.php?t=102289)

pyro.699 12-05-2005 07:30 PM

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

Guest190829 12-05-2005 07:40 PM

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

*I'm still very new to OOP*

pyro.699 12-05-2005 07:43 PM

Im new aswell ^^

umm, so, where what should i put it inside of?

Guest190829 12-05-2005 08:02 PM

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?

pyro.699 12-05-2005 08:09 PM

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(); }


Guest190829 12-05-2005 08:12 PM

Your closing the class before defining any methods, you have to wrap the closing bracket "}" at the end of all you methods.

pyro.699 12-05-2005 08:27 PM

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();


AN-net 12-05-2005 09:14 PM

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.

The Geek 12-05-2005 09:20 PM

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

pyro.699 12-05-2005 09:26 PM

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!


All times are GMT. The time now is 05:30 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01391 seconds
  • Memory Usage 1,772KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete