~george-edison55/jsstudio/addons_site

« back to all changes in this revision

Viewing changes to model.php

  • Committer: Nathan Osman
  • Date: 2011-08-22 04:33:05 UTC
  • Revision ID: admin@quickmediasolutions.com-20110822043305-kk083pea9bjjq5ad
Added ability to download addons.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    
29
29
    function __construct($table_name)
30
30
    {
 
31
        $this->table_name = $table_name;
 
32
        
31
33
        // Attempt to make the connection to the database
32
34
        $this->sql = new mysqli(mysql_server_host,
33
35
                                mysql_server_username,
38
40
        if($this->sql->connect_error != null)
39
41
            throw new Exception($this->sql->connect_error);
40
42
    }
 
43
    
 
44
    public function Query()
 
45
    {
 
46
        // Construct the query
 
47
        $query = "SELECT * FROM {$this->table_name}";
 
48
        
 
49
        // Prepare the statement
 
50
        $statement = $this->sql->prepare($query);
 
51
        if($statement === FALSE)
 
52
            throw new Exception($this->sql->error);
 
53
        
 
54
        // Execute the statement
 
55
        if($statement->execute() === FALSE)
 
56
            throw new Exception($this->sql->error);
 
57
        
 
58
        // Storage for the results
 
59
        $results = array();
 
60
        
 
61
        // We need to get the number of columns returned.
 
62
        $metadata = $statement->result_metadata();
 
63
        while($column = $metadata->fetch_field())
 
64
            $columns[$column->name] = &$results[$column->name];
 
65
        
 
66
        // Now bind the results
 
67
        call_user_func_array(array($statement, 'bind_result'),
 
68
                             $columns);
 
69
        
 
70
        // Return the results
 
71
        $ret = array();
 
72
        
 
73
        // Loop through the rows
 
74
        while($statement->fetch())
 
75
        {
 
76
            $row = array();
 
77
            foreach($results as $key => $value)
 
78
                $row[$key] = $value;
 
79
            
 
80
            $ret[] = $row;
 
81
        }
 
82
        
 
83
        return $ret;
 
84
    }
41
85
}
42
86
 
43
87
?>