php数据库管理系统代码 php中数据库怎么设计

全部积分,请帮我写一段操作数据库的PHP代码呵呵,这个我会代码我写下!加注释...
$link = mysql_connect("localhost", "user", "123");//连接数据库
mysql_select_db("db");//选择数据库
$kkk=_GET('k');
$sql="select * from ttt where kkk='$kkk'";//查询kkk对应content语句
$set=mysqluery($sql);//执行sql语句!
$rs=mysql_fetch_arry($set);
$content=$rs['content'];//取出kkk对应的content
if($content==''){
$content=fff($kkk);//将fff($kkk)赋值给content
//---这里面说加入相应字段是不是指插入数据库里面!如果是
//----那样的话就再加两句:$sa="update ttt set content='$content' where kkk='$kkk'";
//-----$set_a=mysql_query($sa);
}else{
echo $content;//输出$content
}
完成....
你后面说的问题:如果$kkk有重复那我刚才的语句就把所有kkk=$kkk的全部更新了!
你只想选择出第一条记录的话:把查询语句改成这样$sql="select top 1 * from ttt where kkk='$kkk'";
还有就是数据入库的时候要替换什么东西,读取出来的时候还需要还原 。这句话不明白!
呵呵,别忘了给我加分哦!
PHP中链接数据库的代码数据库有很多种类:mysqlphp数据库管理系统代码 , oracle,mssql,db2等等 。PHP操作数据库php数据库管理系统代码的时候,要保证该类型数据库php数据库管理系统代码的扩展已开启 。这里连接的数据库以mysql为例:?php
//数据库服务器地址
$host="localhost";
//连接数据库用户名
$uname="root";
//连接数据库密码
$upass="";
//连接数据库
$conn=mysql_connect($host, $uname,$upass);
//判断连接
if(!$conn){
die("连接数据库失败php数据库管理系统代码!").mysql_errno();
}
//连接成功 , 其他操作省略
?
PHP中写一个数据库查询的类的方法代码要如何写?php
if(!defined("INCLUDE_MYSQL_OK")) {
define("INCLUDE_MYSQL_OK","");
class MySQL_class {
var $debug = true;
var $db,
$id,
$result,/* 查询结果指针 */
$rows,/* 查询结果行数 */
$fields,/* 查询结果列数 */
$data,/* 数据结果 */
$arows,/* 发生作用的纪录行数目 */
$iid;/* 上次插入操作后,可能存在的"AUTO_INCREMENT"属性字段的值 , 如果为"0",则为空 */
var $user, $pass, $host, $charset;
/*
* 请注意用户名和密码是否正确
*/
function Setup ($host, $user, $pass, $charset='utf8') {
$this-host = $host;
$this-user = $user;
$this-pass = $pass;
$this-charset = $charset;
}
function Connect ($db = "") {
global $CFG_MYSQL_INFO;
if (!$this-host) {
$this-host = $CFG_MYSQL_INFO["host"];
}
if (!$this-user) {
$this-user = $CFG_MYSQL_INFO["user"];/* 在这里作修改 */
}
if (!$this-pass) {
$this-pass = $CFG_MYSQL_INFO["passwd"]; /* 在这里作修改 */
}
if (!$this-charset) {
$this-charset = "utf8"; /* 在这里作修改 */
}
if (empty($db))
$this-db = $CFG_MYSQL_INFO["database"];
else
$this-db = $db;
$this-id = @mysql_connect($this-host, $this-user, $this-pass);
if (!$this-id)
return false;
$this-SelectDB($this-db);/* 定位到指定数据库 */
$this-Query("SET NAMES '".$this-charset."'");
return true;
}
function Close(){
@mysql_close($this-id);
}
function SelectDB ($db) {
if(!@mysql_select_db($db, $this-id))
return false;
else
return true;
}
function Begin () {
$this-result = @mysql_query("START TRANSACTION WITH CONSISTENT SNAPSHOT", $this-id);
if (!$this-result)
return false;
return true;
}
function Commit () {
$this-result = @mysql_query("COMMIT", $this-id);
if (!$this-result)
return false;
return true;
}
function Rollback () {
$this-result = @mysql_query("ROLLBACK", $this-id);
if (!$this-result)
return false;
return true;
}
function Escape ($str) {
$escstr = mysql_escape_string($str);
return $escstr;
}
# 普通查询功能,主要用于返回结果是多条记录的情况
# 请使用 Fetch 方法取得每条记录信息
function Query ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-rows = @mysql_num_rows($this-result);
$this-fields = @mysql_num_fields($this-result);
if (!$this-rows) return false;
return true;
}
function QuerySql ($query) {
$ret = @mysql_query($query, $this-id);
if ($ret === false)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-result = $ret;
$this-rows = @mysql_num_rows($this-result);
$this-fields = @mysql_num_fields($this-result);
return true;
}
# 如果查询结果为单条记录时使用,返回结果存储于数组 data 中
function QueryRow ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-rows = @mysql_num_rows($this-result);
$this-data = https://www.04ip.com/post/@mysql_fetch_array($this-result, MYSQL_ASSOC);
//MySQL_ErrorMsg ("不能从查询结果中取得数据 $query");
if (!$this-result || !$this-rows)
【php数据库管理系统代码 php中数据库怎么设计】return false;
return true;
}
# 移动到指定记录行,将该行结果储存于数组 data 中
function Fetch ($row) {
if(!@mysql_data_seek($this-result, $row))
//MySQL_ErrorMsg ("不能定位到指定数据行 $row");
return false;
$this-data = https://www.04ip.com/post/@mysql_fetch_array($this-result, MYSQL_ASSOC);
//MySQL_ErrorMsg ("不能提取指定数据行数据 $row");
if (!$this-data)
return false;
return true;
}
/* 以下方法将作用于 arows */
/* 此方法将作用于 iid */
function Insert ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
$this-iid = @mysql_insert_id($this-id);
return true;
}
function Update ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
if (!$this-arows || $this-arows == -1)
return false;
return true;
}
function Delete ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
return true;
}
function Error (){
return mysql_error()."(".mysql_errno().")";
}
function Errno (){
return mysql_errno();
}
}
/*
* MySQL_ErrorMsg
* 输出错误信息
*/
function MySQL_ErrorMsg ($msg) {
# 关闭可能影响字符显示的HTML代码
echo("/ul/dl/ol\n");
echo("/table/script\n");
# 错误信息
$text= "font color=\"#000000\" style=\"font-size: 9pt; line-height: 12pt\"p系统提示:".$msg."br";
$text .= "错误信息:";
$text .= mysql_error()."br";
$text .= "错误代码:".mysql_errno()."brbr";
$text .= "请稍候再试,如果问题仍然存在 , 请与 a href=https://www.04ip.com/"mailto:wuqiong@igenus.org\"系统管理员/a 联系!";
$text .= "/font\n";
die($text);
}
}
?
一些细节的地方自己修改吧主要是我在别的文件专门定义了全局变量,你看一遍 , 把应改的地方改一下就好了
php数据库管理系统代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php中数据库怎么设计、php数据库管理系统代码的信息别忘了在本站进行查找喔 。

    推荐阅读