易截截图软件、单文件、免安装、纯绿色、仅160KB

实现PHP访问MYSQL数据库的类

PHP的一个数据库操作类,以UTF8格式写入,数据库内直接显示正常中文,防止查询出错
/**
* @author xggxnn
* 本类用于实现有关数据库的访问
*
*/
class DBConnection {
private $host = "";
private $user = "";
private $pass = "";
private $DBname = "";
public $isConnected = false;
/**
* 构造函数将数据库连接的参数初始化
*/
function __construct() {
$this->host = DB_SERVER_NAME;
$this->user = DB_USER_NAME;
$this->DBname = DB_NAME;
$this->pass = DB_PASS;
}
/**
* 连接数据库
*/
function getConnected(){
$this->isConnected = mysql_connect($this->host,$this->user,$this->pass);
if (!$this->isConnected) {// cannot connect to mysql
return $this->isConnected;
} else {//select database
mysql_query('set character_set_client = utf8, character_set_connection =utf8, character_set_results = utf8');
$result = mysql_select_db($this->DBname,$this->isConnected);
if (!$result){// cannot select the database
return $this->isConnected;
} else {
$this->isConnectd = true;
return $this->isConnected;
}
}
}
/**
* 关闭数据库
*/
function closeDB() {
if ($this->isConnected) {
$result = mysql_close($this->isConnected);
if (!$result) {// failed to close mysql connnection
return $result;
} else {
$this->isConnected = false;
return true;
}
} else {
return true;
}
}
/**
* 当连接对象解构时,关闭数据库连接
*/
function __destruct() {
$this->closeDB();
}
}


相关文档:

PHP顺序排序


PHP的算法都有哪些呢?
我还记得上大学那会学数据结构时,了解了:顺序法、冒泡法、二分法以及对线性表以及数据入栈、出栈的操作。
PHP中的顺序法就是对数组元素的逐一比较而得到的。
例如:
 
<?php
function order($php,$k)
{
 $n = count($php);  //计算数组个数
 $php ......

转:Apache+mysql+php在windows下的配置(成功)

http://hi.baidu.com/fish124423/blog/item/c6f9f310190dd779ca80c456.html解决error trying access httpd. conf file.you will need to manually configure the的配置问题
Apache+mysql+php在windows下的配置(成功)
2008-12-16 14:49
Apche下载地点:http://www.apache/org
Or   http://www.51cto.com/html/ ......

JAVA和PHP获取mysql最后插入的自增id值

php和java通用sql语句法
SELECT max(id) from table
该方法在多线程等情况下可能会造成不正确。
java三种方法
1、根据ps的getGeneratedKeys
PreparedStatement ps = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS); //红色是关键
ps.executeUpdate(); //执行后
ResultSet rs = ps.getGeneratedKeys ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号