getMessage();}}public function sRow($sql){$sth ="/>
PHP头条
热点:

phppdo连接数据库-PHP源码


跳至

dbh = new PDO($dsn, $user, $password,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
		} catch (PDOException $e) {
			echo 'Connection failed: ' . $e->getMessage();
		}
	}
	public function sRow($sql){
		$sth = $this->dbh->prepare($sql);
		$sth->execute();
		$ret = $sth->fetchAll(PDO::FETCH_ASSOC);
		return $ret[0];
	}
	public function sRows($sql){
		$sth = $this->dbh->prepare($sql);
		$sth->execute();
		return $sth->fetchAll(PDO::FETCH_ASSOC);
	}
	public function dbInsert($sql){
		$sth = $this->dbh;
		$count = $sth->exec($sql);
		if($count){
			return true;
		}else {
			return false;
		}
	}
	//insert update
	public function dbIUD($sql){
		$sth = $this->dbh;
		$count = $sth->exec($sql);
		if($count){
			return true;
		}else {
			return false;
		}
	}
}

www.phpzy.comtrue/phpyy/49353.htmlTechArticlephppdo连接数据库-PHP源码 跳至 dbh = new PDO($dsn, $user, $password,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8;"));} catch (PDOException $e) {echo Connection failed: . $e->getMessage();}}public function sRow($sql){$sth =...

相关文章

PHP之友评论

今天推荐