<?php
class db{
var $host;// host kome pripada baza
var $db; // ime baze
var $dbuser; //username
var $dbpassword;//password
var $dbconnection;
var $sql;
var $return_array = array();
var $db_sel;
var $number_rows;
var $ins_id;
function get_numberrows(){
return $this->number_rows;
}
function set_numberrows($par){
$this->number_rows=$par1;
}
//function __construct(){
function db(){
//include $_SERVER['DOCUMENT_ROOT']."/dir_config.php";
include $_SERVER['DOCUMENT_ROOT']."/am/configs/config.php";
$this->host=$host;
$this->db=$dbname;
$this->dbuser=$user;
$this->dbpassword=$password;
}
function connect(){
@$this->dbconnection =mysql_connect(@$this->host,@$this->dbuser,@$this->dbpassword);
if (!$this->dbconnection) {
$this->ind_connection='false';
print("Konekcija nije uspela");
exit();
return false;
}else{
$this->db_sel = mysql_select_db($this->db);
if (!$this->db_sel){
print("Da li si siguran da je to ta baza");
exit();
}
return true;
}
}
function exe_queru($par1){
if ($this->connect()) {
$this->sql=$par1;
$this->qry = mysql_query($this->sql);
if (!$this->qry){
if ((mysql_errno()>>0)) {
echo "<br>" . mysql_error() ;
}
print("nesto nije u redu sa upitom");
exit();
}else{
$result = mysql_query($par1);
$this->number_rows=@mysql_num_rows($result);
if ($this->number_rows==0) {
}else{
while ($row = mysql_fetch_array($result)) {
array_push($this->return_array, $row);
}
}
}
}
}
function exe_queru_wr($par1){
if ($this->connect()) {
$this->sql=$par1;
$this->qry = mysql_query($this->sql);
if (!$this->qry){
print("nesto nije u redu sa upitom");
exit();
}else{
//$result = mysql_query($par1);
$this->ins_id =mysql_insert_id($this->dbconnection);
return true;
}
}
}
function instal_database(){
@$this->dbconnection =mysql_connect(@$this->host,@$this->dbuser,@$this->dbpassword);
if (!$this->dbconnection) {
$this->ind_connection='false';
print("Konekcija nije uspela");
exit();
return false;
}else{
//$link = mysql_connect('localhost', 'myname', 'secret');
$list = mysql_list_dbs($this->dbconnection);
$k=0;
while ($row = mysql_fetch_object($list)) {
if ($row->Database==$this->db) {
$k=$k+1;
}
}
if ($k>0) {
}else{
$this->sql="create database ".$this->db ;
$this->qry = mysql_query($this->sql);
if (!$this->qry){
print("nesto nije u redu sa upitom");
exit();
}
}
}
}
}
?>