分享一个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数据库dnname采用默认的latin1字符集,系统升级需要将所有数据转换成utf-8格式,目标数据库为newdbname(建库时使用utf8)
方法一:
步骤一 命令行执行:mysqldump --opt -hlocalhost -uroot -p*** --default-character-set=lantin1 dbname > /usr/local/dbname.sql
步骤二 将 dbname.s ......
启动:net start mySql;
进入:mysql -u root -p/mysql -h localhost -u root -p databaseName;
列出数据库:show databases;
选择数据库:use databaseName;
列出表格:show tables;
显示表格列的属性:show columns from tableName;
建立数据库:source fileNa ......
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 ......
I found a solution to anyone else who may be having this problem.
First start mysql using skip grant tables
root@ns1 [/var/lib/mysql/mysql]# service mysql start --skip-grant-tables
Starting MySQL [ OK ]
now with mysql started, you can repair the mysql/user table
root@ns1 [/var/lib/mysql ......
所以除了给账户权限以外 还有修改 /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的
......