Blogger Information
Blog 33
fans 0
comment 0
visits 24453
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
类与对象,mysqli基础连接 2018年8月29日 23:00
EmonXu的博客
Original
610 people have browsed it

类就是对象的模版,对象是类的一个实例
举例:汽车就是一个类,有以下属性:名称、车型、轴距、排量、长宽高。
对象:具体的车型:丰田霸道:车型SUV,轴距2790,排量3.5,长宽高[5,2,2]

实例

<?php
class Car{
    private $name;
    private $type;
    private $zhouju;
    private $pailiang;
    private $ckg=[];


    public function __construct($name,$type,$zhouju,$pailiang,array $ckg)
    {
        $this->name=$name;
        $this->type=$type;
        $this->zhouju=$zhouju;
        $this->pailiang=$pailiang;
        $this->ckg=$ckg;
    }

    public function __get($name)
    {
        return $this->$name;
    }

    public function __set($name, $value)
    {
        return $this->$name=$value;
    }

}

$prado = new Car('prado','suv',2790,3.5,[5,2,2]);

echo $prado->name,'<br>';
echo $prado->type,'<br>';
echo $prado->zhouju,'<br>';
$prado->zhouju=3000;
echo $prado->zhouju,'<hr>';

运行实例 »

点击 "运行实例" 按钮查看在线实例


mysql增删改查语句:

实例

insert into staff (name,salary) values ('xumeng',10000);
delete from staff where name='xumeng';
update staff set salary=11111 where id='1';
select * from staff ;

运行实例 »

点击 "运行实例" 按钮查看在线实例

数组配置连接参数:

实例

<?php

$db=[
    'host'=>'127.0.0.1',
    'user'=>'root',
    'pass'=>'root',
    'name'=>'php',
    'charset'=>'utf8',
];

运行实例 »

点击 "运行实例" 按钮查看在线实例

连接与检测:

实例

<?php
require 'mysqli/作业config.php'; //配置连接参数
error_reporting(E_ALL ^E_WARNING); //warning级错误不显示

$mysqli =new mysqli($db['host'],$db['user'],$db['pass']); //数据传入连接参数

if ($mysqli->connect_errno){
    die('连接错误'.$mysqli->connect_errno.':'.$mysqli->connect_error);
}else {
    echo '连接成功', '<hr>';
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


手写 mysqli常用属性与方法

手写.jpg

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post