Jump to content

vr4lyfe

Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

vr4lyfe's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. omg .. i m so sorry i wasted everyone's time .. i feel incredibly stupid right now. I assumed the statement was not working since it was supposed to output some db result. Turns out I forgot that my db was empty. But yes, this is the correct syntax. $this->varname->functionname(); Thanks to everyone who replied. Have a great Friday all !!
  2. Those are the two classes in question. I am still nub to OO as this is my first attempt at OO PHP. =] The code in questions is in the constructor of the Session class. Thanks for the help guys PS, I am using PHP Version 5.1.6
  3. class Session { var $sessionID; # var $userID; # var $userhash; # var $userpower; # var $time; # var $connection; # stores a connection to the db once made with the connect function var $errors; # array to contain all errors encountered # CONSTRUCTOR function __construct() { # if session cookie is available pull from session db # if session cookie is not available, log error return false if(isset($_COOKIE['session'])){ $this->connect(); $tmp = $this->$connection->select("SELECT * FROM session"); print_r($tmp); } else { $this->errors[] = "No sessions found"; } } # Creates connection to database that contains the session table function connect(){ if(!include_once('./includes/class_dbLink.php')){ $this->errors[] = "Failed to include required file for database connection."; } else { $this->$connection = new dbLink("session"); } } # Break connection to database function disconnect() { } }
  4. class dbLink { var $server; # server address var $username; # username to connect with var $password; # password to connect with var $database; # name of database to use var $connection; # database connection object var $errors; # array to contain all errors encountered # CONSTRUCTOR function __construct($table_to_use) { # If new connection does not specify which database to connect to, default to localhost. switch($table_to_use){ default: $mysql_server_ip = 'localhost'; break; } $mysql_db_name = 'facetime'; if($_COOKIE['power'] == 0){ # REGISTERED USER [2] || PAID USER [4] || RECRUITER [6] # connect to database as normal account $mysql_user = 'ft_user'; $mysql_password = 'password'; } else { # GUESTS || # connect to database as guest account with only SELECT priviledges $mysql_user = 'ft_guest'; $mysql_password = 'password'; } $this->connect($mysql_server_ip, $mysql_user, $mysql_password, $mysql_db_name); } # Creates connection to database function connect($server,$username,$password,$database){ $this->server = $server; $this->username = $username; $this->password = $password; $this->database = $database; $this->connection = mysql_connect($this->server, $this->username, $this->password); if (!$this->connection) { $this->errors[] = mysql_error(); } else { if(!mysql_select_db($database, $this->connection)){ $this->errors[] = mysql_error(); } } } # Break connection to database function disconnect() { } # QUERIES # This function is the base wrapper to pass any sql statement (insert / delete / select) # Returns result object on success, or false on failure. function query($sql) { if($result = mysql_query($sql, $this->connection)){ return $result; } else { return false; } } # This function utilize the base db wrapper to execute select queries # Return array of results on success to avoid user having to implement mysql_fetch calls. Return false on failure. function select($sql) { if($result = $this->query($sql)){ while($row = mysql_fetch_assoc($result)){ $result_array[] = $row; } return $result_array; } else { $this->errors[] = mysql_error(); return false; } } }
  5. dbLink is my db abstraction class. This syntax work when I am using the class: $connection = new dbLink("session"); $connection->query("sql goes here"); Now I am making another class, which uses and include_once() to integrate the db class and this syntax does not work: $this->connection = new dbLink("session"); $this->connection->query("sql stuff goes here"); Can anyone help me with the proper syntax to make the second code fragment work? Thanks!
  6. Thanks guys.  Consider me informed on ternary operators / concise conditionals now. ;)
  7. Thanks for the quick reply.  I googled it .. and it seems a more common name would be the ternary operator. Very good video on ternary operators @ vtc.com .. its one of their free php tutorial vids.  Its seem though that these things are good only for echo .. lol .. perhaps its just happens to seem that way because all the example is jsut echo example. Can I do something like "(conditional statement) ? function_call(); some_other_functions(); another_function(); : print_error() ;" instead of just "(conditional statement) ? 'some text' : 'some other text'; "
  8. Hi guys.  I am readying some PHP code and it is using this syntax. $x->var = $ x ? 0 : $ x; I know what most its supposed to do (kinda), but just confused about exact syntax of the "?" and ":" notations. Tried searching PHP.net but couldnt find what I was looking for.  Any expect care to point me to a page I can read or explain this to me?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.