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
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 알리기
핀터레스트
텔레그램로
블로그로
페이스북
트위터
카카오스토리
카톡 공유
관련 블로그
로딩중