/var/www/vhosts/sivana.com.br/httpdocs/database/mysql.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php


Class mysql
{

    public 
$query;
    public 
$data;
    public 
$result;
    public 
$rows;
    protected 
$config;
    protected 
$host;
    protected 
$port;
    protected 
$user;
    protected 
$pass;
    protected 
$dbname;
    protected 
$con;

    public function 
__construct()
    {
        try
        {
            
#array com dados do banco
            
include 'database.conf.php';
            global 
$databases;
            
$this->config $databases['local'];
            
# Recupera os dados de conexao do config
            
$this->dbname $this->config['dbname'];
            
$this->host $this->config['host'];
            
$this->port $this->config['port'];
            
$this->user $this->config['user'];
            
$this->pass $this->config['password'];
            
# instancia e retorna objeto
            
$this->con = @mysql_connect"$this->host""$this->user""$this->pass);
            @
mysql_select_db"$this->dbname);
            if ( !
$this->con )
            {
                throw new 
Exception"Falha na conexão MySql com o banco [$this->dbname] em database.conf.php" );
            }
            else
            {
                return 
$this->con;
            }
        }
        catch ( 
Exception $e )
        {
            echo 
$e->getMessage();
            exit;
        }
        return 
$this;
    }

    public function 
query$query '' )
    {
        try
        {
            if ( 
$query == '' )
            {
                throw new 
Exception'mysql query: A query deve ser informada como parâmetro do método.' );
            }
            else
            {
                
$this->query $query;
                
$this->result mysql_query$this->query );
                if(!
$this->result)
                {
                    echo 
mysql_error();exit;
                }
            }
        }
        catch ( 
Exception $e )
        {
            echo 
$e->getMessage();
            exit;
        }
        return 
$this;
    }

    public function 
fetchAll()
    {
        
$this->data "";
        
$this->rows 0;
        while ( 
$row = @mysql_fetch_array$this->resultMYSQL_ASSOC ) )
        {
            
$this->data[] = $row;
        }
        if ( isset( 
$this->data[0] ) )
        {
            
$this->rows count$this->data );
        }
        return 
$this->data;
    }

    public function 
rowCount()
    {
        return @
mysql_affected_rows();
    }


}

/* end file */