首页 > 数据库技术 > 详细

mysql基本操作

时间:2015-05-05 19:08:25      阅读:258      评论:0      收藏:0      [点我收藏+]

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 “删除失败”;
}

mysql基本操作

原文:http://www.cnblogs.com/zhengs/p/4479483.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!