본문 바로가기

Program/MySQL

MySql 기본 폼

<?

// Server hosting the database
$config['dbserver']                        = "localhost";

// Username that has permissions to the database
$config['dbuser']                        = "유저아이디";

// Password for the database
$config['dbpass']                        = "디비 암호";

// Name of the database
$config['dbname']                        = "디비 네임";

  class sql {

    ; function connect() {    
      global $config; 

      if ($this->dbh == 0) {
        if (!$config[persistent]) {
           $this->dbh = mysql_connect($config['dbserver'],$config['dbuser'],$config['dbpass']);
        }
        else {
           $this->dbh = mysql_pconnect($config['dbserver'],$config['dbuser'],$config['dbpass']);
        }

      }
      if (!$this->dbh) {
        $this->not_right("Unable to connect to the database!");
      }
      mysql_select_db($config['dbname'],$this->dbh);
    
    }

    ; function graberrordesc() {
      $this->error=mysql_error();
      return $this->error;
    }

    function graberrornum() {
      $this->errornum=mysql_errno();
      return $this->errornum;
    }

    ; function do_query($query) {
   
      $this->sth = mysql_query($query,$this->dbh);
      if (!$this->sth) {
        $this->not_right("Unable to do_query: $query");
      }

      return $this->sth;
    }

    ; function fetch_array($sth) {
     
      $this->row = mysql_fetch_array($sth);
   
      return $this->row;
    }

    ; function finish_sth($sth) {
      return @mysql_free_result($this->sth);
    }

    ; function total_rows($sth) {
      return mysql_num_rows($this->sth);
    }

     ; function num_fields($sth) {
       return mysql_num_fields($this->sth);
     }

     ; function field_name($sth,$i) {
       return mysql_field_name($this->sth,$i);
     }

    ; function not_right($error) {
      $this->errordesc = mysql_error();
      $this->errornum  = mysql_errno(); 
      echo "<b>SQL ERROR:</b> <i>$error</i><br> $this->errordesc: $this->errornum";
    }

  }

?>

'Program > MySQL' 카테고리의 다른 글

Mysql - myisamchk.exe 사용하기  (0) 2007.10.04
mysql쿼리문  (0) 2007.10.03