<?php
// $Id: database.php,v 1.1 2007/08/09 02:26:41 nishi Exp $

require_once("DB.php"); // use PEAR::DB

# $db = new Database();
# $db->create_goods();

class Database {
    var $db;
    var $db_user = "galatea";
    var $db_pass = "galatea";
    var $db_host = "localhost";
    var $db_name = "galatea_db";
    
    function Database() {
        $db_string = "pgsql://$this->db_user:$this->db_pass@$this->db_host/$this->db_name";
        $this->db = DB::connect($db_string);
        
        if (PEAR::isError($this->db)) {
            echo sprintf(
                "<pre>\n"
                . "message: %s\n\n"
                . "code: %s\n\n"
                . "userInfo: %s\n\n"
                . "debugInfo: %s\n"
                . "</pre>\n",
                $this->db->getMessage(),
                $this->db->getCode(),
                $this->db->getUserInfo(),
                $this->db->getDebugInfo()
                );
            exit;
        }
    }
    
    function create_goods() {
        $sql = <<<EOD
CREATE TABLE goods(
    code SERIAL NOT NULL PRIMARY KEY,
    name VARCHAR(64),
    yomi VARCHAR(64),
    price INTEGER
);

INSERT INTO goods VALUES(1, 'りんご', 'りんご', 200);
INSERT INTO goods VALUES(2, 'みかん', 'みかん', 50);
INSERT INTO goods VALUES(3, 'スイカ', 'すいか', 1000);
INSERT INTO goods VALUES(4, 'メロン', 'めろん', 1500);
INSERT INTO goods VALUES(5, 'バナナ', 'ばなな', 120);
INSERT INTO goods VALUES(6, '夏みかん', 'なつみかん', 200);

EOD;
        $rs = $this->db->query($sql);
        $this->db->disconnect();
    }
}

?>
