引子 .今天排查代码,一路飞,到数据库,
<span>1</span><span>$this->slave()->select('sina_user_id, sina_nickname, password')->from(self::Table_User_Info)</span>
显然到这里确定了表.user_info;
这个文件没有load->database();
顾名: slave() 是从库,追溯slave() 果然在这里组合了库名字符串,
<span>1</span><span> public function slave($dbName = 'default') </span><span>2</span> { <span>3</span> }
func 里面load->database();
查loader里的database();有下面这句,
<span>1</span><span><strong>require</strong>_once(BASEPATH.'database/DB.php');</span>
找到DB.php;
<span>1</span><span> if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = BASEPATH.'config/'.ENVIRONMENT.'/database.php'))</span>
这个文件里面多个数据库属性的引入,详见核心文件分析.
终于找到了database.php 位置
<span> 1</span><span>// Default DB Config </span><span> 2</span><span>$db['default_master']['hostname'] = 'localhost'; </span><span> 3</span><span>$db['default_master']['username'] = 'admin'; </span><span> 4</span><span>$db['default_master']['password'] = '12345678'; </span><span> 5</span><span>$db['default_master']['database'] = ' '; </span><span> 6</span><span>$db['default_master']['port'] = 3306; </span><span> 7</span><span>$db['default_master']['dbdriver'] = 'mysql'; </span><span> 8</span><span>$db['default_master']['pconnect'] = FALSE; </span><span> 9</span><span>$db['default_master']['db_debug'] = TRUE; </span><span>10</span><span>$db['default_master']['cache_on'] = FALSE; </span><span>11</span><span>$db['default_master']['cachedir'] = ''; </span><span>12</span><span>$db['default_master']['char_set'] = 'utf8'; </span><span>13</span><span>$db['default_master']['dbcollat'] = 'utf8_general_ci'; </span><span>14</span><span>$db['default_master']['swap_pre'] = ''; </span><span>15</span><span>$db['default_master']['autoinit'] = TRUE; </span><span>16</span><span>$db['default_master']['stricton'] = FALSE;</span>
追溯数据库完毕.
以上就介绍了一次简单的数据库追溯,包括了require方面的内容,希望对PHP教程有兴趣的朋友有所帮助。