php mysql space는 php Mysql 클래스를 참조하여 학습하고 익힐 수 있습니다.

WBOY
풀어 주다: 2016-07-29 08:40:09
원래의
1096명이 탐색했습니다.

复aze代码 代码如下:


class Mysql
{
private $conn;
비공개 $host;
비공개 $사용자 이름;
비공개 $password;
비공개 $dbname;
비공개 $pconnect;
비공개 $charset;
공용 함수 __construct(array $params = null)
{
if (!empty($params)) {
foreach ($params as $k => $v) {
$this->$k = $v;
}
}
}
공용 함수 connect()
{
$fun = $this->pconnect ? 'mysql_pconnect': 'mysql_connect';
$this->conn = $fun($this->host, $this->사용자 이름, $this->password);
$this->conn && $this->query('이름 설정' . $this->charset);
$this->conn && mysql_select_db($this->dbname, $this->conn);
}
공용 함수 getInstance()
{
return $this->conn;
}
공용 함수 쿼리($sql)
{
return mysql_query($sql, $this->conn);
}
공용 함수 fetchOne($sql)
{
$data = $this->fetchRow($sql);
$data[0] 반환;
}
공용 함수 fetchCol($sql)
{
$tmp = $this->fetchAll($sql, MYSQL_NUM);
foreach($tmp를 $v로) {
$data[] = $v[0];
}
}
공용 함수 fetchRow($sql)
{
$result = $this->query($sql);
$data = mysql_fetch_row($result);
mysql_free_result($result);
$data를 반환합니다.
}
공용 함수 fetchAssoc($sql)
{
$result = $this->query($sql);
$data = mysql_fetch_assoc($result);
mysql_free_result($result);
$data를 반환합니다.
}
공용 함수 fetchAll($sql, $type = MYSQL_ASSOC)
{
$result = $this->query($sql);
while ($tmp = mysql_fetch_array($result, $type)) {
$data[] = $tmp;
}
$data를 반환합니다.
}
공용 함수 fetchPairs($sql)
{
$result = $this->query($sql);
while ($tmp = mysql_fetch_row($result)) {
$data[$tmp[0]] = $tmp[1];
}
$data를 반환합니다.
}
공용 함수 insert($table, array $bind)
{
$cols = array();
$vals = 배열();
foreach($bind as $col => $val) {
$cols[] = $col;
$vals[] = $val;
설정 해제($bind[$col]);
}
$sql = "INSERT INTO "
. $테이블
. ' (`' . implode('`, `', $cols) . '`) '
. 'VALUES ('' . implode('', '', $vals) . '')';
$stmt = $this->query($sql, $this->conn);
$result = $this->affectedRows();
$결과 반환;
}
공용 함수 getLastInsertId()
{
return mysql_insert_id($this->conn);
}
공용 함수 영향을 받은Rows()
{
return mysql_affected_rows($this->conn);
}
공용 함수 업데이트($table, array $bind, $where = '')
{
$set = array();
foreach ($bind as $col => $val) {
$set[] = '`' . $col . "` = '" . $발 . "'";
}
$sql = "UPDATE `"
. $테이블
. '세트' . implode(', ', $set)
. (($where) ? " WHERE $where" : '');
$stmt = $this->query($sql, array_values($bind));
$result = $this->affectedRows();
$결과 반환;
}
공용 함수 delete($table, $where = '')
{
/**
* DELETE 문 작성
*/
$sql = "DELETE FROM "
. $테이블
. (($where) ? " WHERE $where" : '');
/**
* 명령문을 실행하고 영향을 받은 행 수를 반환합니다.
*/
$stmt = $this->query($sql);
$result = $stmt ? mysql_affected_rows($this->conn) : $stmt;
$결과 반환;
}
공용 함수 close()
{
$this->conn && mysql_close($this->conn);
}
}
?>

以上就介绍了php mysql 空间 一个php Mysql类 可以参考school习熟悉下,包括了php mysql 空间方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!