增删除改查语句(懂些后台语言)

原创 李仁伟前端笔记 随笔 服务器语言 394阅读 2017-08-30 14:20:19 举报

$sql = "insert into info(name,mobile,pass)values('小强','13112345678','123456')"; //增加

$sql = "delete from info where id=1";//删除
$sql = "update info set mobile='13600000000'where id=2"; //修改

$sql = "select *from info";//可以写各种查询
$result = mysql_query($sql);//执行查询语句

header("Content-Type: text/html; charset=utf-8");//语言类型避免 乱码
$link = @mysql_connect("localhost","root","") or die('错误'.mysql_error());// 服务器ip 用户名 密码 die 输出()中的内容 终止后面的程序
//echo $link;
//info 是文件名
//选库函数 mysql_select_db();
mysql_select_db("abc");

// 执行sql语句 sql语句 以字符串 存在
mysql_query("set names utf8");
//$sql = "insert into info(id,name)value('3','小强')";
//echo
//$sql = "insert into info(name,mobile,pass)values('小强','13112345678','123456');"; //增加
//mysql_query($sql);
//$sql = "delete from info where id=1";//删除
//$sql = "update info set mobile='13600000000'where id=2"; //修改
//查
$sql = "select *from info";//可以写各种查询
$result = mysql_query($sql);//执行查询语句 //展现
//echo $result;//返回资源:结果集
//$rs = mysql_fetch_array($result); //结果集参数 当前记录抽取出来 指向下一条记录

//MYSQL_ASSOC : 关联数组
//MYSQL_NUM:索引数组
//MYSQL_BOTH:混合数组

//mysql_fetch_assoc($result);//抽取 关联数组
//while ($rs = mysql_fetch_array($result,MYSQL_BOTH)) {

//while ($rs = mysql_fetch_assoc($result)) {
//mysql_fetch_row($result);// 索引数组

//print_r($rs);//var_dump($rs);

die;//终止后面的看不到
mysql_close();

查询表里某个字段值是否存在。
<?php
if($_GET[id]){
sleep(1);
$conn=mysql_connect('localhost','root','');
mysql_select_db('test',$conn);
$sql="SELECT * FROM user WHERE name='$_GET[id]'";
$q=mysql_query($sql);

if(is_array(mysql_fetch_row($q))){
  echo "用户名已经存在"; 
}else{
  echo "用户名可以使用"; 
}

}
?>

$sql = "select Users.,Answer. from Users,Answer where Users.U_id = Answer.Uid and Answer.Qid = '$Que_id' and Answer.A_re = 0 order by Answer.A_date Asc ";

                 //找出问题为5的所有回答 并且pid=0(无回复)
                $result=mysql_query($sql);
                $num=mysql_num_rows($result);  //获取行数

                if($num == '0'){
                  echo "暂无回答";
                }else{
                  echo "有回答";
                }
评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复