Ejemplo n.º 1
0
 public function checkStock()
 {
     $quantiteStock = ConnectionPDO::getInstance()->getQuantiteStock($this->idArticle);
     if ($quantiteStock > $this->quantiteCommandee) {
         return 0;
     } else {
         return $quantiteStock;
     }
 }
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
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;