PHP操作数据库:insert create 操作_PHP教程

WBOY
Release: 2016-07-13 17:44:59
Original
904 people have browsed it

/*  2011.7.27

*/

  $demos =new Demo();
  $dbname="create database tools";
  $dbtabla="create table admin(name varchar(200),pass varchar(200))";
  $values="insert into admin values('Feihacker','tools')";
  $demos->CreateDB($dbname);
  $demos->CreateDB($dbtabla,"tools");
  $demos->CreateDB($values,"tools");
  class Demo
  {     /*执行插入操作
       */
      public function CreateDB($sql,$name){
          $conn =mysql_connect("localhost","root","root");//创建连接对象
        if(!empty($name)) //创建表 //判断是否为空
          {
              mysql_select_db($name,$conn); //选定数据库
              if(!mysql_query($sql)){     echo"error". mysql_error();} //mysql_query();执行sql语句
            mysql_close($conn); //关闭连接
          }
          else
          {
              if(!mysql_query($sql)){     echo"error". mysql_error();}
             mysql_close($conn);
          }
      }

  }

?>
 from:菲 blog

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478704.htmlTechArticle?php /* 2011.7.27 */ $demos =new Demo(); $dbname=create database tools; $dbtabla=create table admin(name varchar(200),pass varchar(200)); $values=insert into admin values(Feihacker...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!