/ Published in: PHP

That's not complete enough! but as useful as a knife :/
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class Database{ private $host; private $user; private $pwd; private $rows; private $error; private $result; private $dbName; private $connection; private $isReady; public function __construct(){ $this->result = null; $this->isReady = false; } /* setters */ public function setHost($host){ $this->host = $host; } public function setUser($user){ $this->user = $user; } public function setPassword($pwd){ $this->pwd = $pwd; } public function setDbName($dbName){ $this->dbName = $dbName; } /* other interfaces */ public function init($host=null,$user=null,$pwd=null,$dbName=null){ $this->setHost($host); $this->setUser($user); $this->setPassword($pwd); $this->setDbName($dbName); $this->isReady = true; } public function select($dbName){ $this->setDbName($dbName); } public function query($sql){ } public function connect(){ $this->connection = mysql_connect($this->host,$this->user,$this->pwd) or die("Could not connect to database. please check your credentials."); $this->select($this->dbName); $this->query("SET NAMES 'utf8'",$this->connection); //persian support } public function isConnected(){ if($this->connection) return true; return false; } public function disconnect(){ $this->connection = null; } public function countRows($selectMode = true){ if($selectMode) } public function loadRows(){ $this->rows[] = $r; return $this->rows; } public function siftDown($dataStack){ return $dataStack; } foreach($dataStack as $p=>$data){ $safeData[$p] = $data; } return $safeData; } public function secure($data){ } }//Database class ?> <?php //usage require_once 'path/to/Database.class.php'; $db = new Database(); //Creating new object $db->init("localhost","test_root","test_pwd!","test_db"); //initializing by credentials. $db->connect(); //unicode support $test_value = $db->siftDown($test_value); //preventing harmful inputs $something_testy_else = $db->siftDown($something_testy_else); $db->query("SELECT * FROM test_table WHERE test_field = '$test_value' AND second_test_field = '$something_testy_else' LIMIT 1"); if($db->countRows()==1) $dbdata = $db->loadRows(); //returns a numeric/associative array as the result (MYSQL_BOTH) //TODO: To Process $dbdata $db->disconnect(); ?>
Comments
