实现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.ini文件.
如下.
1. short_open_tag = Off
如果改成On
我们可以在php中
<?= $variable?>来代替 <?php echo $variable ?>
2. asp_tags = Off
如果改成On
同样可以在php中
<%= $variable %> 来替代<?php echo $variable ?>
怎么样. 方便吧????
继续研究~~~~~~!!!!~~!~!~!~!~!~!~! ......
PHP的算法都有哪些呢?
我还记得上大学那会学数据结构时,了解了:顺序法、冒泡法、二分法以及对线性表以及数据入栈、出栈的操作。
PHP中的顺序法就是对数组元素的逐一比较而得到的。
例如:
<?php
function order($php,$k)
{
$n = count($php); //计算数组个数
$php ......
最近在折腾 PHP + MYSQL
的编程。了解了一些 PHP SQL 注入攻击
的知识,于是写了这篇文章 http://www.xiaohui.com/weekly/20070314.htm,总结一下经验。在我看来,引发 SQL 注入攻击
的主要原因,是因为以下两点原因:
1. php 配置文件 php.ini 中的 magic_quotes_gpc
选项没有打开,被置为 off
2. 开发 ......
JAVA文件操作总结
File类
File f = new File(path);
path为实际路径,该路径可以是文件,或文件夹,也可以是不存在的。
f.exists() 可以判断该路是否存在。
f.isDirectory() 可以判断是否是文件夹。
f.mkdirs(); 递归创建文件夹
File和输入输出流之间纽带FileInutStream,FileOutputStream
URL url = new URL(strUr ......
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 ......