public function checkStock() { $quantiteStock = ConnectionPDO::getInstance()->getQuantiteStock($this->idArticle); if ($quantiteStock > $this->quantiteCommandee) { return 0; } else { return $quantiteStock; } }
static function getConnection() { try { if (!isset(self::$instance)) { self::$instance = new PDO("mysql:host=" . self::$host . "; dbname=" . self::$db . ";", self::$username, self::$password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8')); } return self::$instance; } catch (Exception $e) { throw $e; } }
function __construct($nome, $primaryKey, $tabela, $atributos = NULL, $filhos = NULL) { $this->nome = $nome; $this->primaryKey = $primaryKey; $this->tabela = $tabela; /* array(array('ClassFilho', 'indiceAssociativo', 'entity/'), array('ClassFilho2', 'indiceAssociativo2', 'entity//')) */ $this->filhos = $filhos; if (is_null($atributos) or count($atributos) == 0) { $conexao = ConnectionPDO::getConnection(); $rs = $conexao->query("SHOW COLUMNS FROM {$tabela}"); if (!$rs) { unset($conexao); throw new Exception("Erro ao buscar campos da tabela {$tabela}."); } $atributos = array(); while ($row = $rs->fetch()) { $atributos[] = $row['Field']; } unset($conexao); } $this->atributos = $atributos; }
function __autoload($class) { if (class_exists($class)) { return true; } $dir = __DIR__ . DIRECTORY_SEPARATOR; $ext = '.php'; if (file_exists($dir . $class . $ext)) { require_once $dir . $class . $ext; } else { exit('Couldn\'t open class ' . $class . '!'); } } $settings = array('driver' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'schema' => 'test', 'username' => 'root', 'password' => ''); $dns = $settings['driver'] . ':host=' . $settings['host'] . ';port=' . $settings['port'] . ';dbname=' . $settings['schema']; $con = new ConnectionPDO($dns, $settings['username'], $settings['password']); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>ConnectionMSi Test</title> <style> body { margin: 0; padding: 0; background-color: #3477B9; font-family: Verdana, Arial, sans-serif; } #main { display: block;