A simple Database.php file

<?php

class Database
{

	public $user='my_user';
	public $password='my_password';
	public $db='my_db';
	public $host='localhost';
	public $link;
	public function connect()
	{
		
		$link = mysql_connect($this->host, $this->user, $this->password);
		mysql_select_db($this->db);
	}
	public function query ($string)
	{
		return mysql_query($string);
	}
	
	public function fetchAll($string)
	{
		
		
		$query = "select * from `$string`";
		
		$result = $this -> query($query);
		return $result;
	}
}
Advertisements

6 thoughts on “A simple Database.php file

    • Hi,
      i have seen this in php site

      “The Singleton pattern is one of the more controversial patterns. Critics argue that Singletons introduce Global State into an application and tightly couple the Singleton and its consuming classes. This leads to hidden dependencies and unexpected side-effects, which in turn leads to code that is harder to test and maintain.

      Critics further argue that it is pointless to use a Singleton in a Shared Nothing Architecture like PHP where objects are unique within the Request only anyways. It is easier and cleaner to create collaborator object graphs by using Builders and Factory patterns once at the beginning of the Request.

      Singletons also violate several of the “SOLID” OOP design principles and the Law of Demeter. Singletons cannot be serialized. They cannot be subtyped (before PHP 5.3) and won’t be Garbage Collected because of the instance being stored as a static attribute of the Singleton. ”

      Should i use singleton pattern in my application development?

      Like

  1. One of the best programming solutions is to use patterns. Any of them. Yes, singleton is controversial, but with it any further development will be easier. Also, if You’re not using any patterns You should try. Best practice is to use some framework. The most popular pattern is of course MVC. You can learn it by using (example) CodeIgniter. I think that CI is the best for beginners. Good, with great support and nice manual.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s