Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

·ÖÏíÒ»¸ö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 " .


Ïà¹ØÎĵµ£º

apacheºÍmysqlÖØÆôÃüÁî

 
ÐÞ¸Älinux·þÎñÆ÷µÄhttpÅäÖÃÖ®ºó£¬±ØÐëÖØÆôApache·þÎñ£¬ÃüÁîΪ£º /etc/rc.d/init.d/httpd restart
chown -R mysql:mysql Ŀ¼Ãû ¸Ä±äÎļþÊôÐÔ
mysqladmin -u root -p password 'new password' ÉèÖÃÃÜÂë
apt-get remove ɾ³ýÈí¼þ
apt-get clean ÇåÀí
/etc/rc.d/init.d/mysqld restart
php ¾ÍÅäÖÃÁËsession Ö÷ ......

11 advanced MySQL questions

 

Explain MySQL architecture
. - The front layer
takes care of network connections and security authentications, the
middle layer does the SQL query parsing, and then the query is handled
off to the storage engine. A storage engine could be either a default
one supp ......

mysqlĬÈÏÊÇÖ»ÄÜ´Ólocalhost·ÃÎÊ

 ËùÒÔ³ýÁ˸øÕË»§È¨ÏÞÒÔÍâ »¹ÓÐÐÞ¸Ä /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µÄ
......

mysql±äÁ¿ÀàÐÍ

9.3. Óû§±äÁ¿
¿ÉÒÔÏÈÔÚÓû§±äÁ¿Öб£´æÖµÈ»ºóÔÚÒÔºóÒýÓÃËü£»ÕâÑù¿ÉÒÔ½«Öµ´ÓÒ»¸öÓï¾ä´«µÝµ½ÁíÒ»¸öÓï¾ä¡£Óû§±äÁ¿ÓëÁ¬½ÓÓйØ
¡£Ò²¾ÍÊÇ˵£¬Ò»¸ö¿Í»§¶Ë¶¨ÒåµÄ±äÁ¿²»Äܱ»ÆäËü¿Í»§¶Ë¿´µ½»òʹÓᣵ±¿Í»§¶ËÍ˳öʱ£¬¸Ã¿Í»§¶ËÁ¬½ÓµÄËùÓбäÁ¿½«×Ô¶¯ÊÍ·Å¡£
Óû§±äÁ¿µÄÐÎʽΪ@var_name
£¬ÆäÖбäÁ¿Ãûvar_name
¿ÉÒÔÓɵ±Ç°×Ö· ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ