Jump to content

fsarcani-marco

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Everything posted by fsarcani-marco

  1. A possible solution can be to create a GLOBALS environmet as connection pool and for every access I verify if the connection is not closed? $GLOBALS[' but in my free web host I can't modify php.ini.
  2. I thinked that the constructor is always called for base class because if I'm creating a derived object I will create base object and calling construct method after call derived object and call construct of derived object without explict specification of call costructor base object in costructor of derived object. :-\ It's very strange how to work php for object oriented programming. Why constructor is called construct if it isn't automatically called in creation derived object constructor ? I do not understand what's the advantage. For example that I submit I will not use but it was to know how to work php in oo. Don't worry I know pattern to remove tightly coupled object. It was only to test how to work php. I'm using free web hosting in awardspace. I can't use permanent link for free space account. In my first idea was create a session environment connection pooling but it's impossible in awardspace web hosting free because this company for free account don't offer permanent link to mysql or mysqli. The second idea was create a connection for every session, but this can create an overflow of resource depending of the users number. The third idea was create a user session connection for every user but is a waste. The final idea was create a connection link and open and close for every query. If you have some advices to solve the limit of permanent link with an elegant solution, please explain me . :'( Thank you for your reply.
  3. I have mysqli object in Database class base: class Database { private $dbLink = null; public function __construct() { if (is_null($this->dbLink)) { // load db information to connect $init_array = parse_ini_file("../init.ini.inc", true); $this->dbLink = new mysqli($init_array['database']['host'], $init_array['database']['usr'], $init_array['database']['pwd'], $init_array['database']['db']); if (mysqli_connect_errno()) { $this->dbLink = null; } } } public function __destruct() { $this->dbLink->close(); } } Class derived is Articles where I use object dBLink in base (or parent) class and I can't access to mysqli methods (dbLink member of base class): Articles class: require_once ('./includes/db.inc'); class Articles extends Database{ private $id, .... .... $visible = null; public function __construct() { // Set date as 2009-07-08 07:35:00 $this->lastUpdDate = date('Y-m-d H:i:s'); $this->creationDate = date('Y-m-d H:i:s'); } // Setter .... .... // Getter .... .... public function getArticlesByPosition($numArticles) { if ($result = $this->dbLink->query('SELECT * FROM articles ORDER BY position LIMIT '.$numArticles)) { $i = 0; while ($ret = $result->fetch_array(MYSQLI_ASSOC)) { $arts[$i] = $ret; } $result->close(); return $arts; } } } In my front page php I use article class: include_once('./includes/articles.inc'); $articlesObj = new articles(); $articles = $articlesObj->getArticlesByPosition(1); var_dump($articles); :'( Notice: Undefined property: Articles::$dbLink in articles.inc on line 89 Fatal error: Call to a member function query() on a non-object in articles.inc on line 89 If I remove constructor on derived class Articles result don't change :'( Please help 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.