实现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 ?>
怎么样. 方便吧????
继续研究~~~~~~!!!!~~!~!~!~!~!~!~! ......
//去除 script 脚 本
function delScript($string){
$pregfind = array("/<script.*>.*<\/script>/siU",'/on(mousewheel|mouseover|click|load|onload|submit|focus|blur)="[^"]*"/i');
$pregreplace = array('','');
$string = preg_replace($pregfind, $pregreplace, $string);
return $str ......
PHP的算法都有哪些呢?
我还记得上大学那会学数据结构时,了解了:顺序法、冒泡法、二分法以及对线性表以及数据入栈、出栈的操作。
PHP中的顺序法就是对数组元素的逐一比较而得到的。
例如:
<?php
function order($php,$k)
{
$n = count($php); //计算数组个数
$php ......
如果同意系统中同时存在install mysql和no—install mysql,那么怎样进行两个版本的切换使用呢?又会遇到什么样的问题呢?
首先,install mysql的mysql服务是默认启动的,在任务管理器进程中可以看到几条sql的字眼,如mysqld.exe,sqlbrowser。这是install mysql的服务。那么通过快捷方式或navicat就能启动使用install ......
原文
(英文)地址:
http://www.phpit.net/article/using-curl-php
版权声明:署名-非商业性使
用-禁止演绎 2.0
摘要:
在这篇文章中主要讲解
php_curl库的知识,并教你如何更好的使用php_curl。
简介
你可能在你的编写PHP脚
本代码中会遇到这样的问题:怎么样才能从其他站点获取内容呢?这里有几个解决方式 ......