search
Homephp教程php手册PHP面向对象的使用教程 简单数据库连接

PHP面向对象的使用教程 简单数据库连接

Jun 13, 2016 pm 12:36 PM
phpuseobjectTutorialdatabaseofSimplekindthisconnectFor

这个PHP的数据库连接类,应该算是最简单的一个连接类了,也是最好明白的一个连接类.作为开始PHP面向编程之旅的一个开始吧.我看了很多网上流传的MYSQL数据库连接类,都太复杂拉.以我己见,真的没必要搞得那么复杂,一个小小的数据库连接.
   下面是我的写的类:

 
 Class createdb    //类的开始
 {
 var $db= "localhost";//数据库地址;
 var $dbname = "root";//用户名;
 var $dbpwd = "";//密码;
 var $dbtable = "text";//使用的数据库
 var $conn;    //数据库连接;
 var $result;    //结果集
 var $mysql ="select * from text";    //执行的mysql
 var $row;     //结果集中找数据
 function createconn()   //这个类方法是开始一个conn连接,然后开始选择数据库
 {
  $this->conn = mysql_connect($this->db,$this->dbname,$this->dbpwd);
   mysql_select_db($this->dbtable,$this->conn);

 } 
 function getresule() //这个是得到一个结果集
 {
  $this->result = mysql_query($this->mysql,$this->conn);
 }
 function getrow() //创建一个向前的结果集指针
 {
  $this->row = mysql_fetch_array($this->result);
  return $this->row;

 }

 }//类结束,开始调用类来读mysql数据库数据.
 $bb = new createdb;  //类实例化
 $bb->createconn();// 调用类的连接
 $bb->getresule(); //调用类得到结果集
 while($bb->getrow()){      //调用类创建指针向前读循环读数据,

  echo($bb->row["voteid"]);
  echo($bb->row["vote"]);

 }
?>

 
   这个是放写好的,没优化.不过呢,调试好了可以使用.以后我都会继续写多几个教程类,想文件上传或其他的,一步一步教大家.
   还有css+div布局教程和实例,再以后的日子里我也会慢慢教大家.其实做网站真的好累
太多东西学了

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools