2010-07-05 68 views
0

我有一個令人討厭的問題。我想擺脫某個特定的數據庫字段,但我不確定它調用哪些代碼。有沒有辦法找出這個字段的使用/調用方式(除了文本搜索代碼;這是相當無用的,看看字段如何命名爲'電子郵件')?監視某個數據庫字段的使用情況

乾杯

+0

在SQL Server中存在有sp_depends可 - 你可以嘗試尋找的:mysql相當於sp_depends可 - 的「SQL Server」。 – amelvin 2010-07-05 13:35:42

回答

2

我會首先搜索文件中的表名,然後只搜索包含表名稱的字段名稱的表。

我寫了一個程序來做我自己的目的。它構建表和字段的內存列表,並將這些表與這些字段相關聯。然後它循環遍歷表,搜索包含表名的代碼文件,然後在這些文件中搜索找到的表中的字段。我建議您採用類似的方法。

1

設置MySQL記錄所有查詢一段時間可能會有幫助。查詢會給你提示在哪裏尋找

1

蠻力 - 建立一個測試實例 - 刪除列 - 並練習你的測試套件。

+0

不妨做到這一點,因爲無論如何你都會在更改後運行所有測試。你不是嗎? – 2010-07-05 15:24:03

+0

我會,如果系統不是太老,不包含預定義的測試;) – Robbert 2010-07-06 11:00:50

-1

你應該在PHP中做到這一點我希望

例如:

<?php 
class Query 
{ 
    var $command; 
    var $resource; 
    function __construct($sql_command = '') 
    { 
     $this->command = $sql_command; 
    } 

    public function setResource($resource) 
    { 
     $this->resource = $resource; 
    } 
} 

//then you would have some kind of database class, but here we would modify the query method. 

class Database 
{ 
    function query(Query $query) 
    { 
     $resource = mysql_query($query->command); 
     $query->setResource($resource); 

     //Then you can send the class to the monitor 
     QueryMonitor::Monitor($query); 
    } 
} 

abstract class QueryMonitor 
{ 
    public static Monitor(Query $query) 
    { 
     //here you use $query->resource to do monitoring of queryies 
     //You can also parse the query and gather what query type it was:- 
     //Select or Delete, you can also mark what tables were in the Query 
     //Even meta data so 
     $total_found = mysql_num_rows($query->resource); 
     $field_table = mysql_field_table ($query->resource); 
     //Just an example.. 
    } 
} 
?> 

顯然,這將是比這更先進的,但你可以建立一個系統來監控每個查詢,每個查詢元在日誌文件或我們的數據

+0

我認爲他正在尋找一個事後解決方案,而不是一個新的方式來編寫未來的項目... – ceejayoz 2010-07-05 13:21:44

+0

哦,好吧,這是我的錯,我很抱歉 – RobertPitt 2010-07-05 13:23:22

0

在該表上創建一個插入觸發器,該表監視該列上的插入。

同時創建一個名爲monitor另一個表只有一列email

使該表中插入NEW.email字段的值到monitor.email以及在真正的表。

這樣你就可以運行你的應用程序,並檢查是否有任何非空值的監控表