Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class app {
- //server
- var $server = 'localhost';
- //database
- var $dbase = '';
- //username
- var $user = 'root';
- //pass
- var $pass = '';
- //connection id
- var $connection = 0;
- /**
- * app::app()
- *
- * @param $server
- * @param $dbase
- * @param $user
- * @param $pass
- * @return void
- **/
- function __construct($server = '', $dbase = '', $user = '', $pass = '') {
- if ($server!=''){
- $this->server = $server;
- }
- $this->dbase = $dbase;
- $this->user = $user;
- $this->pass = $pass;
- }
- function connect() {
- if ($this->server!='' && $this->dbase!=''){
- $this->connection=mysql_connect($this->server,$this->user,$this->pass);
- if ($this->connection){
- mysql_select_db($this->dbase,$this->connection);
- }
- }
- mysql_query("SET NAMES UTF8;");
- return ($this->connection);
- }
- function disconnect() {
- @mysql_close($this->connection);
- }
- function free($result){
- return mysql_free_result($result);
- }
- function query($sql='') {
- //provjera da li smo spojeni na bazu i ako nismo onda pokusaj spajanja
- if (!$this->connection){
- $this->connect();
- }
- if ($this->connection && $sql!=''){
- $record_set = mysql_query($sql);
- if(mysql_errno() !=0){
- echo $sql."<br>";
- echo mysql_errno() . ": " . mysql_error() . "\n<hr>";
- }
- return $record_set;
- } else {
- return false;
- }
- }
- } // class
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement