HOME 개발팁 class mysql 함수

프로그램 작업하다 좋은 팁, 정보, 테스트를 기록하는 곳입니다.


PHP | class mysql 함수

페이지 정보

작성자 굿스웹 작성일19-08-04 09:58 조회603회 댓글0건

본문

class goodsweb_db {
 
private $db = array();
private $connection;

        private $_host    = "호스팅";
        private $_username = "사용자";
private $_password = "비밀번호";
private $_database = "데이타베이스";
private $_datatype = "utf8"; //문자셋



 
public function db($args = array()) {
$this->db['server'] = $this->_host;
$this->db['username'] = $this->_username;
$this->db['password'] = $this->_password;
$this->db['database'] = $this->_database; }
 
public function connect() {
$this->connection = mysqli_connect($this->db["server"], $this->db["username"], $this->db["password"]);
$this->select_db(); }
 
public function disconnect() {
mysqli_close($this->connection);
$this->connection = null; }
 
public function select_db() {
mysqli_select_db($this->connection, $this->db["database"]); }
 
public function query($sql) {
  $result = $this->result = mysqli_query($this->connection, $sql);
  if($result){
mysqli_query($this->connection, "set names ".$this->_datatype);
            return $result;
  } else {
          return 0;
  }
  }

public function fetch($sql) {
  $result = $this->result = mysqli_query($this->connection, $sql);
  $data_array = array();
          while ($_row =  mysqli_fetch_object($result)) {
              $data_array[] = $_row;
          }
          return $data_array;
  }
 
//public function fetch() {
// $this->result = mysqli_fetch_array($this->result); }
 
public function is_connected() {
return ($this->connection) ? true : false; }


  public function clean($dirty) {
if (!is_array($dirty)) {
$dirty = ereg_replace("['\")(;|`,<>]", "", $dirty);
$dirty = mysqli_real_escape_string($this->connection, trim($dirty));
$clean = stripslashes($dirty);
return $clean; };
$clean = array();
foreach ($dirty as $p=>$data) {
$data = ereg_replace("['\")(;|`,<>]", "", $data);
$data = mysqli_real_escape_string($this->connection, trim($data));
$data = stripslashes($data);
$clean[$p] = $data; };
return $clean; }
 
}

$db = new goodsweb_db();
$db->connect();

//$dirty = "dfgfdg fd@#$`11``'''`%^%Y";
//$clean = $db->clean($dirty);
//echo"<pre>";
//print_r ( $clean );
//echo"</pre>";

$account = $db->query("update surl set q_datetime = now() where q_num='1'");
//$row = mysqli_fetch_array($db->query("select * from surl"));
echo"<pre>";
print_r ( $account );
echo"</pre>";

$row = $db->fetch("select * from surl order by q_num desc");
echo"<pre>";
print_r ( $row );
echo"</pre>";

$db->disconnect();


#mysql함수 #class

[주소복사] https://www.goodsweb.kr/?u=D41B3u5x
SNS 알리기
핀터레스트
텔레그램로
블로그로
카카오스토리
카톡 공유

관련 블로그
로딩중


2명  IP : 3.15.♡.113
001 141.♡.61.111 오류안내 페이지
(/bbs/login_check.php)
002 157.♡.39.52 오류안내 페이지
(/bbs/qadownload.php)

접속자
  • 오늘 : 5
  • 어제 : 305
  • 최대 : 874
  • 전체 : 402,132

검색로봇(Robots) 최근 방문시간
  • NAVER : 14시간 전
  • GOOGLE : 1일 전
  • BING : 2일 전
  • DAUM : 5일 전

ETH : 0x8abf3B748ab78828AE07685e4fd53d1a606f18D3



페이스북 네이버 블로그 굿스웹 쇼핑몰 네이버 카페 굿스웹 트위터 굿스웹 티스토리 Google Play