Home  >  Article  >  Backend Development  >  PHP database operation: insert create operation_PHP tutorial

PHP database operation: insert create operation_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:44:59974browse

/* 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
{                                    /*Execute the insertion operation
*/
Public function CreateDB($sql,$name){
             $conn =mysql_connect("localhost","root","root");//Create connection object
If(!empty($name)) //Create table //Determine whether it is empty
              {
                              mysql_select_db($name,$conn); //Selected database
If(!mysql_query($sql)){ echo"error".mysql_error();} //mysql_query();Execute sql statement
                 mysql_close($conn); //Close the connection
          }
         else
              {
If(!mysql_query($sql)){ echo"error".mysql_error();}
                  mysql_close($conn);
          }
}

}

?>
from:fei 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...
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