Home >php教程 >php手册 >PHP mysql基本语句指令

PHP mysql基本语句指令

WBOY
WBOYOriginal
2016-06-06 19:48:051115browse

1 /* 选择数据库 2 use test; 3 */ 4 5 /* 显示所有的数据库 6 show databases; 7 */ 8 9 /* 删除表/数据库 10 drop database test1; 11 delete from user1 where id=4; 12 */ 13 14 /* 创建表 15 CREATE TABLE user1( 16 id int primary key auto_increment

<span> 1</span> <span>/*</span><span>选择数据库
</span><span> 2</span> <span>   use test;
</span><span> 3</span>    <span>*/</span>
<span> 4</span>    
<span> 5</span>    <span>/*</span><span> 显示所有的数据库
</span><span> 6</span> <span>   show databases;
</span><span> 7</span>    <span>*/</span>
<span> 8</span>    
<span> 9</span>    <span>/*</span><span>删除表/数据库
</span><span>10</span> <span>   drop database test1;
</span><span>11</span> <span>   delete from user1 where id=4;
</span><span>12</span>    <span>*/</span>
<span>13</span>    
<span>14</span>    <span>/*</span><span>创建表
</span><span>15</span> <span>   CREATE TABLE user1(
</span><span>16</span> <span>id int primary key auto_increment,
</span><span>17</span> <span>name varchar(32) not null,
</span><span>18</span> <span>password varchar(64) not null,
</span><span>19</span> <span>email varchar(128) not null,
</span><span>20</span> <span>age tinyint unsigned not null);</span><span>*/</span>
<span>21</span> 
<span>22</span>   <span>/*</span><span>插入数据
</span><span>23</span> <span>  insert into user1(name,password,email,age)
</span><span>24</span> <span>  values('daomul',md5('daomul'),'975052664@qq.com','22');
</span><span>25</span>   <span>*/</span>
<span>26</span>   
<span>27</span>   <span>/*</span><span>查询数据
</span><span>28</span> <span>  select * from user1;
</span><span>29</span>   <span>*/</span>
<span>30</span>   
<span>31</span>   <span>/*</span><span>输入中文的问题解决
</span><span>32</span> <span>  set character_set_client-gbk;
</span><span>33</span> <span>  set character_set_result-gbk;
</span><span>34</span>   
<span>35</span> <span>  #显示所有字符类型 :show variables like '%char%';
</span><span>36</span>   
<span>37</span>   <span>*/</span>

 

1、查询一行数据

   "select name from user1 where age=' " .$age. " '  limit 0,1;"  //控制在0-1条数据

2、模糊查询

   "select name from user1 where email like ' % " $email " %' "; 

3、批量执行 sql语句

   3.1  批量执行dml语句

        (1  $sql="$sql1;$sql; ....";  

            或者 :$sqls="" ;   $sqls.="";   $sqls.=""; ....

       (2   mysqli::multi_query($sqls); //执行操作,并返回 操作的数目。

   3.2  批量执行dml语句

   具体事例:见  http://www.cnblogs.com/daomul/p/3381782.html

 4、自我复制:测试高度的数据

  insert into emp(name,grade,email,school,salary,remark)select name,grade,email,school,salary,remark from emp;

 

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