·ÖÏíÒ»¸ö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 " .
Ïà¹ØÎĵµ£º
MySQLÖÐʹÓô洢¹ý³Ì
ʹÓÃCallableStatementsÖ´Ðд洢¹ý³Ì
mysql°æ±¾:5.0
Connector/JµÄ°æ±¾:3.1.1ÒÔÉÏ(java.sql.CallableStatement½Ó¿ÚÒÑÍêȫʵÏÖ,³ýÁËgetParameterMetaData()·½·¨)
MySQLµÄ´æ´¢¹ý³ÌÓï·¨ÔÚMySQL²Î¿¼ÊÖ²áµÄ"´æ´¢¹ý³ÌºÍº¯Êý"Ò»ÕÂ.
http://www.mysql.com/doc/en/Stored_Procedures.html
ÏÂÃæÊÇÒ»¸ ......
http://blog.c1gstudio.com/archives/602
nagios_plugin°²×°Ê±ÕýÈ·¹ØÁªmysqlºó»áÔÚlibexecϲúÉúcheck_mysqlÎļþ
/usr/local/nagios/libexec/check_mysql -h
check_mysql v2034 (nagios-plugins 1.4.13)
Copyright (c) 1999-2007 Nagios Plugin Development Team
< ......
ÐÞ¸Ä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 Ö÷ ......
MysqlÊý¾Ý¿âÊÇÒ»¸ö¶àÓû§£¬¶àÏ̵߳ĹØϵÐÍÊý¾Ý¿â£¬ÊÇÒ»¸ö¿Í»§»ú/·þÎñÆ÷½á¹¹µÄÓ¦ÓóÌÐò¡£ËüÊǶԸöÈËÓû§ºÍÉÌÒµÓû§ÊÇÃâ·ÑµÄ.
MysqlÊý¾Ý¿â¾ßÓÐÒÔÏÂÓŵ㣺
1.ͬʱ·ÃÎÊÊý¾Ý¿âµÄÓû§µÄÊýÁ¿²»ÊÜÏÞÖÆ
2.¿ÉÒÔ±£´æ³¬¹ý5ǧÍòÌõµÄ¼Ç¼
3.ÊÇÄ¿Ç°Êг¡ÉÏÏÖÓÐÊý¾Ý¿â²úÆ·ÖÐÔËÐÐËÙ¶È×î¿ìµÄÊý¾Ý¿âϵͳ
4.Óû§È¨ÏÞÉèÖüòµ¥¡¢ÓÐ ......
mysqlÊǷdzּÌÁ¬½Óº¯Êý¶ømysqliÊÇÓÀÔ¶Á¬½Óº¯Êý¡£Ò²¾ÍÊÇ˵
mysqlÿ´ÎÁ´½Ó¶¼»á´ò¿ªÒ»¸öÁ¬½ÓµÄ½ø³Ì¶ømysqli¶à´ÎÔËÐÐmysqli½«Ê¹ÓÃͬһÁ¬½Ó½ø³Ì,´Ó¶ø¼õÉÙÁË·þÎñÆ÷µÄ¿ªÏú
ÓÐЩÅóÓÑÔÚ±à³ÌµÄʱºò£¬Ê¹ÓÃnew mysqli('localhost', usenamer', 'password', 'databasename');×ÜÊDZ¨´í£¬Fatal error: Class 'mysqli' not found in ......