·ÖÏíÒ»¸ömysqlÀà~
<?php
/**
* ²Ù×÷mysql
µÄ»ù´¡À࣬ÆäËüÓëmysqlÓйصÄÀ඼¼Ì³ÐÓÚ´Ë»ùÀà
*
* ´ËclassÖеÄ$table¶¼ÊÇÒѾ°üº¬±íǰ׺µÄÍêÕû±íÃû
*
* ver 20090717
* ʹÓ÷¶Àý
* $db = new DB('localhost','root','password','database','utf8');
* $db->debug = true;
* $db->primaryKeys = array (
* 'table_1' => 'id',
* 'table_2' => 'id2'
* );
* $db->find('table_1', 1);
* $db->findAll('table_2', '*', 'catid=1', 'id desc');
* ……
*/
class DBBase extends Base {
public $debug; //µ÷ÊÔ
public $primaryKeys = array(); //É趨¸÷±íµÄÖ÷¼ü£¬ÔÚ´´½¨ÀàʵÀýºó±ØÐëÉ趨±íÖ÷¼ü $db->primaryKeys(array('±í1'=>'Ö÷¼ü×Ö¶Î
1','±í2'=>'Ö÷¼ü×Ö¶Î2'))
public $queryCount = 0;
public $haltOnError = true;
public $displayError=true;
public $queryID;
public $connected = false;
public $tableFields = array();
public $dbhost;
public $dbuser;
public $dbpwd;
public $dbname;
public $dbcharset;
public $pconnect = false;
public function __construct($host, $user, $pwd, $database = null, $charset = null, $pconnect = null) {
$this->dbhost = $host;
$this->dbuser = $user;
$this->dbpwd = $pwd;
$this->dbname = $database;
$this->dbcharset = $charset;
$this->pconnect = $pconnect;
}
public public function connect()
{
if ($this->pconnect) {
@mysql_pconnect($this->dbhost, $this->dbuser, $this->dbpwd) || die('<b>MySQL
ERROR:</b> ' . mysql_error());
} else {
@mysql_connect($this->dbhost, $this->dbuser, $this->dbpwd) || die('<b>MySQL ERROR:</b> ' . mysql_error());
}
if ($this->dbname != null) {
$this->selectdb($this->dbname);
}
$this->connected = true;
}
public function selectdb($dbname) {
$this->dbname = $dbname;
mysql_select_db($this->dbname) || die('<b>MySQL ERROR(mysql_selectt_db):</b> ' . mysql_error());
$serverVersion=$this->serverVersion();
if ($this->dbcharset && $this->serverVersion()>='4.1') {
mysql_query("SET NAMES " .
Ïà¹ØÎĵµ£º
À´Ô´£ºhttp://www.sudone.com/linux/mysql_debug.html
×÷ÕߣºAyou
ÎÒÒ»Ö±ÊÇʹÓÃmysqlÕâ¸öÊý¾Ý¿âÈí¼þ£¬Ëü¹¤×÷±È½ÏÎȶ¨£¬Ð§ÂÊÒ²ºÜ¸ß¡£ÔÚÓöµ½ÑÏÖØÐÔÄÜÎÊÌâʱ£¬Ò»°ã¶¼ÓÐÕâô¼¸ÖÖ¿ÉÄÜ£º
1¡¢Ë÷ÒýûÓн¨ºÃ£»
2¡¢sqlд·¨¹ýÓÚ¸´ÔÓ£»
3¡¢ÅäÖôíÎó£»
4¡¢»úÆ÷ʵÔÚ¸ººÉ²»ÁË£»
1¡¢Ë÷ÒýûÓн¨ºÃ
Èç¹û¿´µ½mysqlÏûºÄµÄcpuºÜ´ó£¬¿ÉÒÔÓ ......
1¡¢mysqlÊý¾Ý¿âÓÐÁ½ÖÖÇý¶¯£º
MySQL Connector/J Driver¡¢MMMysql driver¡£
2¡¢µ¼Èëµ¼³öÊý¾Ý¿âÃüÁ£¨binĿ¼Ï£©
µ¼³ö£ºmysqldump -u root -p bokele >c:/mysql.sql --default-character-set=gbk
µ¼È룺C:\mysql\bin\> mysql -u root -p
˵Ã÷£ºC:\mysql\bin\±íʾ½øÈëmysql³ÌÐò ......
ÔÚÍøÕ¾½¨Éè»òÕßÔËÓªÖУ¬Èç¹û MySQL server ÊǷdz£·±Ã¦£¬¿ÉÒÔ¿ªÆô query cache ÒÔ¼ÓËÙ»ØӦʱ¼ä£¬¿ªÆô·½·¨¿ÉÒÔÔÚ my.cnf 裡Ãæ¼ÓÈëÒÔÏÂÏîÄ¿: (Redhat ÏÂÃæÊÇ /etc/my.cnf£»Debian ÊÇÔÚ etc/mysql
/my.cnf).
query_cache_size = 64M
query_cache_type = 1
query_cache_limit = 1048576
ÒÔÉÏÓï·¨µÄÉ趨ÀïÃ棬 ......
ËùÒÔ³ýÁ˸øÕË»§È¨ÏÞÒÔÍâ »¹ÓÐÐÞ¸Ä /etc/mysql/my.cnf
ÕÒµ½ bind-address = 127.0.0.1 ÐÞ¸ÄΪ bind-address = 0.0.0.0
ÖØÆômysql : sudo /etc/init.d/mysql restart
·ñÔò»á±¨ ERROR 2003 (HY000): Can't connect to MySQL server on 'x.x.x.x' (111)
ºÃ°É ÎÒÊÇmysql²ËÄñ ÒÔÇ°¶¼ÊÇ×ßlocalhostµÄ
......
java£¨jsp)ʹÓÃMySqlÊý¾Ý¿â,ÖÐÎÄÂÒÂëµÄÍêÕû½â¾ö·½°¸
mysqlÊÇÒ»¸öСÐ͵ĿªÔ´µÄÊý¾Ý¿â£¬ÓÃÀ´×ÔѧһЩ¼¼ÊõÊÇÊ®·Ö·½±ãµÄ¡£µ«Ê¹ÓÃmysql´æ´¢Êý¾Ý£¬Ò²»áÓöµ½Ò»Ð©·Ç³£¶ñÐĵÄÎÊÌ⣬È磺ÖÐÎÄÂÒÂëÎÊÌâ¡¢javaÇý¶¯³ÌÐòÎÞ·¨Ê¹ÓõÄÎÊÌ⣨ÒѾ½â¾ö£¬Ïê¼û£ºhttp://hi.baidu.com/lauo1988/blog/item/ff0da655bd3e2eceb745ae0b.html)¡£
......