PHP connection mysql database -


class db {     function connect()     {         $lines    = file('secret');         $uid      = trim($lines[0]);         $pw       = trim($lines[1]);         $dbserver = trim($lines[2]);         $dbname   = trim($lines[3]);          $link = mysqli_connect($dbserver, $uid, $pw, $dbname) or die('could not connect: ' . mysqli_error());         return $link;     }     function query($sql)     {         $result = mysqli_query($this->connect(), $sql) or die('query failed' . mysqli_error());         return $result;     }     function close()     {         mysqli_close($this->connect());     } } 

//can switch these code contain private members? //i tried many things fails everytime

private class properties can set using private keyword.

more info: php manual: visibility

for example:

<?php /**  * define myclass  */ class myclass {     public $public = 'public';     protected $protected = 'protected';     private $private = 'private';      function printhello()     {         echo $this->public;         echo $this->protected;         echo $this->private;     } }  $obj = new myclass(); echo $obj->public; // works echo $obj->protected; // fatal error echo $obj->private; // fatal error $obj->printhello(); // shows public, protected , private 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -