• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

will this class work?

Zandarin

New Member
hi, im new to classes and i was reading some information on them and I would like to know if this would work?

PHP:
<?php

//Database Variables
$dbhost = "localhost";
$dbuser = "test";
$dbpass = "test";
$dbname = "test";
$id = $_GET['id'];
//Database Connection Function
function dbopen() {
mysql_connect("$dbhost","$dbuser","$dbpass");
}
//Database Selection Function
function dbselect() {
mysql_select_db("$db");
}
//Database Close And Flush Function
function dbclose() {
mysql_close();
}

//Begin Mysql Classes For Getting Data

/*** NOTES ***/
/*
To call a template use $get->$template;
To call Content from database use $db->$content;
To display the template use $db->$template;
To Display the content use $db->$select;
*/
/*** End Notes ***/

class db {
var $insert;
var $update;
var $select;
var $delete;
var $fetch;
var $template;
function db($insert=\"mysql_query("insert .$content. into .$tbl");\", $update = "mysql_query("update .$content. with .$ucontent. where .$condition.");\", $select = "mysql_query("select .$id. from .$tbl.");\", $delete = "mysql_query("delete .$content. from .$tbl. where .$condition.");\", $fetch = "mysql_fetch_array($select);", $template = "mysql_query("select .$tmp. from templates");\""); {
$this->insert=$insert;
$this->update=$update;
$this->select=$select;
$this->delete=$delete;
$this->fetch=$fetch;
$this->template=$template;
}
}
//End Mysql Classes For Getting Data

//template functions
function replace() {
$content = "{content}";
$content = ereg_replace('{content}', $db->$select, $content);
print $content;
}
?>

if it wont work could you help me fix it and explain how the class works...
classes are so confusing....
 
it won't work.. you mess up private with public property. the constructor itself will also fail on declaration since its arguments are invalid..

just pm me and i will give you a short course on PHP classes.. :)
 
bloodyveins said:
it won't work.. you mess up private with public property. the constructor itself will also fail on declaration since its arguments are invalid..

just pm me and i will give you a short course on PHP classes.. :)
i think tere is no problem with public private parts ,the simple declarations are

$this->insert=$insert;

there is no mess up of private and puclic variables.
yes the constructor may not work since arguments seems to be invalid ...
 
oh my goodness... this is not as simple as you think, dude.
please review the code he made.
what're all the functions used to?
why must they be declared but never be used??

look at the class, there are only private properties. how can you fetch the query string and all the related results?? oww.. you must show me how it works if you're that sure it will.. :)
 
sorry i have not noticed the query strings are being used in the constructor which are not allowed there ,infact you cannot assign a constructor arguments to another variable like this
class B{
var $t;
function B($t=$myvar){
}
}
thats why the code will not work
but he has written functions which are never used ,no problem its up to him he may write something which is not being used .. even you can write a story there :)
 
nag said:
but he has written functions which are never used ,no problem its up to him he may write something which is not being used .. even you can write a story there :)

so what's it for? to confuse others? to waste resources? for developers, every microsecond of script execution is valuable, so it's important to write code effectively and efficiently.
 
Back
Top