zoukankan      html  css  js  c++  java
  • mysql基本操作


    Conn.php    //连接mysql数据库

    <?php
    $id=mysql_connect("127.0.0.1","root","") or die('连接失败:'.mysql_error());
    if(mysql_select_db("test_moonlitshiny ",$id))
    echo"";
    else
    echo('数据库连接失败:'.mysql_error());
    mysql_query("set names utf8");
    ?>
    Select.php    //搜索数据库

    <?php
    $id=mysql_connect("127.0.0.1","root","") or die('连接失败:'.mysql_error());
    if(mysql_select_db("test_moonlitshiny ",$id))
    echo"";
    else
    echo('数据库连接失败:'.mysql_error());
    mysql_query("set names utf8");
    $lineid=1;
    $query=mysql_query("select * from test_moonlitshiny where ID='$lineid'");
    if($query==true)
    {
    while($myrow=mysql_fetch_array($query))
    {
    $helloworld=$myrow[q1];
    $hello=$myrow[q2];
    Echo $helloworld;
    Echo $hello;
    }
    }

    insert.php    //插入数据

    <?php
    $id=mysql_connect("127.0.0.1","root","") or die('连接失败:'.mysql_error());
    if(mysql_select_db("test_moonlitshiny ",$id))
    echo"";
    else
    echo('数据库连接失败:'.mysql_error());
    mysql_query("set names utf8");

    $n1=”hello”;
    $n2=”world”;
    $n3=”helloworld”;
    $query="insert into test_moonlitshiny(q1,q2,q3)values('$n1','$n2','$n3')";
    $result=mysql_query($query);
    if($result==true)
    {
    Echo “HELLO ~WORLD!”;
    }
    Else
    {
    Echo “oh~~thx~~~”;
    }
    ?>

    Update   //更新
    <?php
    $id=mysql_connect("127.0.0.1","root","") or die('连接失败:'.mysql_error());
    if(mysql_select_db("test_moonlitshiny ",$id))
    echo"";
    else
    echo('数据库连接失败:'.mysql_error());
    mysql_query("set names utf8");
    $id=1;
    $n1=”hello”;
    $n2=”world”;
    $n3=”helloworld”;
    $query=mysql_query("update test_moonlitshiny set q1='$n1',q2='$n2',q3='$n3'  where ID='$id'");
    if($query==true)
    {
    Echo “HELLO ~WORLD!”;
    }
    Else
    {
    Echo “oh~~thx~~~”;
    }
    ?>

    Delete.php      //删除
    <?php
    $id=mysql_connect("127.0.0.1","root","") or die('连接失败:'.mysql_error());
    if(mysql_select_db("test_moonlitshiny",$id))
    echo"";
    else
    echo('数据库连接失败:'.mysql_error());
    mysql_query("set names utf8");
    $id=1;
    $query=mysql_query(“delete from test_moonlitshiny where ID=’$id’”);
    If($query==true)
    {
    Echo “删除成功”;
    }
    Else
    {
    Echo “删除失败”;
    }

  • 相关阅读:
    I2C调试
    linux读取cpu温度
    看react全家桶+adtd有感
    react学习1(搭建脚手架,配置less,按需引入antd等)
    去掉console.log,正式环境不能有console.log
    Vue的minix
    数组去重我总结的最常用的方法,其他不常用就不写了
    inline-block bug解决方法
    vue中使用less/scss(这是2.0 3.0就不需要手动配置了只需要安装依赖就行了)
    Vue 调用微信扫一扫功能
  • 原文地址:https://www.cnblogs.com/love1226/p/4475142.html
Copyright © 2011-2022 走看看