Recommended (free):PHP7
PHP7.3.5 encapsulation class Access mysql database
Model.class.php
table=$t; } private function conn(){ $servername = "localhost"; $username = "root"; $password = "133"; $dbname = "myweb"; // 创建连接 if($conn=mysqli_connect($servername, $username, $password, $dbname)){ return $this->connect=$conn; } } //select查询 public function select(){ $this->conn(); $sql="SELECT * FROM {$this->table}"; $rst=mysqli_query($this->connect,$sql); while($row=mysqli_fetch_assoc($rst)){ $rows[]=$row; } return $rows; } } ?>
function.inc.php
index.php
select(); echo ''; print_r($rows); echo ''; ?>Copy after login
Related free learning recommendations:mysql video tutorial
The above is the detailed content of Introducing PHP7.3.5 encapsulation class to access mysql database. For more information, please follow other related articles on the PHP Chinese website!