连接&解除功能 [英] Connect & Disconnetcting functions

查看:55
本文介绍了连接&解除功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在构建一个由DB驱动的网站,我有一个页面(settings.php)

包含在内在每个可查看的页面上。在settings.php中,我有一些

函数,所以我不必全部输入,或者如果

有任何变化就全部修改它们。


出于同样的原因,我想创建一个连接到mySQL的函数

DB。

我所拥有的是:


########################################### ####

函数doConnect(){

$ db = mysql_connect(" host"," user"," pass");

mysql_select_db(" data",$ db);

};


函数doDisConnect(){

mysql_close($ db);

};

########################## #####################

然后我想从settings.php为
包括:


_______________________________________________

doConnect();


$ get_user = mysql_query( SELECT id,customerID,hits FROM

customerID WHERE customerID =''$ user''",$ db );


if($ data = mysql_fetch_array($ get_user)){

$ sql =" UPDATE customerID SET hits = hits + 1 WHERE

customerID =''$ user''" ;;

} else {

$ sql =" INSERT INTO customerID(customerID,hits)VALUES

(''user'',1)" ;;

};

$ addhit = mysql_query($ sql);


doDisConnect();

_______________________________________________


这个函数是一个计数器,但这并不重要。为什么我不能获得这个工作?或者我应该完全不同吗?


我现在想知道,在很多页面中使用它之前...

先谢谢。问候knoakske

Hi there,

I''m building a DB-driven site, and i have one page (settings.php) that
is included on each viewable page. In settings.php i have a few
functions, so i do not have to type them all, or modify them all if
anything changes..

For the same reason i want to create a function to connect to a mySQL
DB.
What i have is:

###############################################
function doConnect(){
$db = mysql_connect("host", "user", "pass");
mysql_select_db("data",$db);
};

function doDisConnect(){
mysql_close($db);
};
###############################################

And then i want to run them from a page where settings.php is
included:

_______________________________________________
doConnect();

$get_user = mysql_query("SELECT id, customerID, hits FROM
customerID WHERE customerID=''$user''",$db);

if ($data = mysql_fetch_array($get_user)) {
$sql = "UPDATE customerID SET hits = hits + 1 WHERE
customerID =''$user''";
}else{
$sql = "INSERT INTO customerID (customerID, hits) VALUES
(''$user'', 1)";
};
$addhit = mysql_query($sql);

doDisConnect();
_______________________________________________

this function is a counter, but that isn''t really important. Why can''t
i get this to work? Or should i do it totally different?

I''d like to find out now, before i have used it in a lot of pages...

Thanks in advance. Greetings knoakske

推荐答案

db = mysql_connect(" host"," user"," pass");

mysql_select_db(" data",
db = mysql_connect("host", "user", "pass");
mysql_select_db("data",


db);

};


函数doDisConnect(){

mysql_close(
db);
};

function doDisConnect(){
mysql_close(


db);

};

######### ######################################


然后我想从一个页面运行它们,其中settings.php包含




_______________________________________________

doConnect();

db);
};
###############################################

And then i want to run them from a page where settings.php is
included:

_______________________________________________
doConnect();


这篇关于连接&解除功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆