| 
									
										
										
										
											2019-05-14 15:28:42 -06:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2019-05-17 12:28:19 -06:00
										 |  |  | require_once('./config.php'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 15:28:42 -06:00
										 |  |  | class Db { | 
					
						
							|  |  |  |   private $dbh; | 
					
						
							|  |  |  |   public $last_error_info; | 
					
						
							|  |  |  |   function __construct() { | 
					
						
							| 
									
										
										
										
											2019-05-17 12:28:19 -06:00
										 |  |  |     $this->dbh = new PDO('mysql:host=localhost;dbname=lexiconga;charset=utf8', DB_USER, DB_PASSWORD); | 
					
						
							| 
									
										
										
										
											2019-05-14 15:28:42 -06:00
										 |  |  |     $this->dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); | 
					
						
							|  |  |  |     $this->last_error_info = null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function execute ($query, $params = array()) { | 
					
						
							|  |  |  |     // Run a query that doesn't require a result to be returned
 | 
					
						
							|  |  |  |     $stmt = $this->dbh->prepare($query); | 
					
						
							|  |  |  |     if ($stmt->execute($params)) { | 
					
						
							|  |  |  |       $this->last_error_info = null; | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     $this->last_error_info = $stmt->errorInfo(); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   public function query ($query, $params = array()) { | 
					
						
							|  |  |  |     // Run a query that returns results
 | 
					
						
							|  |  |  |     $stmt = $this->dbh->prepare($query); | 
					
						
							|  |  |  |     $stmt->execute($params); | 
					
						
							|  |  |  |     $this->last_error_info = $stmt->errorInfo(); | 
					
						
							|  |  |  |     return $stmt; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function lastInsertId () { | 
					
						
							|  |  |  |     return $this->dbh->lastInsertId(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public function errorInfo () { | 
					
						
							|  |  |  |     return $this->dbh->errorInfo(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |