jeudi 28 juillet 2016

show data using design pattern

I want to show data from the database and also from the csv file using the FACTORY PATTERN, as I wrote a code and in the code I only wrote for the database but the code is not working but its as rough code so can anyone tell me the right one?

<?php
interface IDatabase {
    function connect();
}

class Database implements IDatabase
{

    private $db_host;
    private $db_name;
    private $db_user;
    private $db_pass;
    private $connection = null;
    public $user_id;
    public function __construct($uid)
    {$this->user_id=$uid;}
   /* {

        $this->db_host = $host;
        $this->db_name = $name;
        $this->db_user = $user;
        $this->db_pass = $pass;
    }
public static function construct()
  {
    $this->db = new db();
  }*/
    public function connect()
    {
        if ($this->connection === null) {

        $host = "localhost";
        $user = "root";
        $pass = "";
        $name = "cart";

        $this->connection = new mysqli($host, $user, $pass, $name);

   if(mysqli_connect_error()) {
            trigger_error("Failed to conencto to MySQL: " . mysqli_connect_error(),
                 E_USER_ERROR);
        }

   }
        }
    public function query($sql)
    {
        $result = $this->connection->query();
        $records = array();
        while ($row = $result->fetch_assoc()) {
            $records[] = $row;
        }
        return $records;
    }
//  $db1= database::construct();

    $query = $uid->query("SELECT * FROM user_info");
foreach($query as $row=>$val)
{ echo '<tr>';
                echo '<td>'.$val['id'].'</td>';
                echo '<td>'.$val['username'].'</td>';
                echo '<td>'.$val['email'].'</td>';
                echo '<td>'.$val['password'].'</td>';
                echo '</tr>';

    }
    class csv implements IDatabase
    {

    }

?>

Aucun commentaire:

Enregistrer un commentaire