作业3

来源:互联网 发布:事业单位会计软件 编辑:程序博客网 时间:2024/06/03 18:46
<?phpspl_autoload_register(function($className){    $className = str_replace("\\", "/", $className);    include __DIR__ . "/" .  $className . ".class.php";}); class Mysqlhelper {     public $user='root';     public $host=localhost;     private $password='wjy990129';     protected $connection;     protected $sql;     protected $dbname="test";     protected $result;     public function __construct($host,$user,$password,$dbname) {         $this->host=$host;         $this->password=$password;         $this->uesr=$user;         $this->dbname=$dbname;         $this->connection=new \mysqli($host,$user,$password,$dbname);     }     public function insert(string $ststement)     {         $this->sql=$statement;         $this->connection->query($this->sql);         if($this->connection->error)         {             return $this->connection->errno;         }         else         {             return $this->connection->insert_id;         }     }     public function delete(string $ststement)     {         $this->sql=$statement;         $this->connection->query($this->sql);         if($this->connection->error)         {             return $this->connection->errno;         }         else         {             return $this->connection->affected_rows;         }     }     public function update(string $ststement)     {         $this->sql=$statement;         $this->connection->query($this->sql);         if($this->connection->error)         {             return $this->connection->errno;         }         else         {             return $this->connection->affected_rows;         }     }     public function select(string $ststement)     {         $this->sql=$statement;         $result=$this->connection->query($this->sql);         if($this->connection->error)         {             return $this->connection->errno;         }         else         {             return $result->fetch_all(MYSQLI_BOTH);         }     }     protected function return_last_sql()     {         return $this->sql;     }     protected function return_last_result()     {         return $this->result;     }     public function __destruct() {         if($this->connection)            $this->connection->close() ;     } } $mypdo = null;try{    $usr = 'root';    $psw = 'balabala';    $mypdo = new PDO('mysql:dbname=score;host=127.0.0.1',$usr,$psw);} catch (Exception $e) {    echo $e->getMessage();}$sth1 = $mypdo->prepare($statement);$id = "5";$sth1->bindParam(":id", $id);$sth1->execute();var_dump($sth1->fetchAll(PDO::FETCH_ASSOC));
原创粉丝点击