本来の動作をしていないアプリケーションを継承しました。データベースが正しく接続されていないという問題を特定しました。プログラマーは、データベースが接続されているかどうかを評価し、接続されていない場合は接続するために「attachPaymentDatabase()」関数を呼び出すと思われるこの関数を作成しました。
function attachPaymentDatabaseIfNotDoneAlready()
{
global $db;
global $hasPaymentDatabaseAttached;
// Determine if we have attached the payment tables, and if not, add them.
$hasPaymentDatabaseAttached = false;
try {
// this new way should work the best-- looking for PAY.
$alldb = queryall($db, "PRAGMA database_list;");
for ($i = 0; $i < count($alldb); $i++)
{
$alldb[$i] = array_change_key_case($alldb[$i], CASE_LOWER);
if (strtolower($alldb[$i]['name']) == 'pay')
{
debugEmail("condition 1 worked.");
$hasPaymentDatabaseAttached = true;
break;
}
}
// if its name changed this will also work
if (!$hasPaymentDatabaseAttached)
{
$r = @$db->querySingle("SELECT * FROM PAY_PARAMETER;");
$hasPaymentDatabaseAttached = true;
debugEmail("condition 2 worked.");
}
}
catch(Exception $e)
{
}
if (!$hasPaymentDatabaseAttached)
{
debugEmail("nothing worked.");
attachPaymentDatabase();
}
}
上記で使用したタイムスタンプ付きの定義済みメッセージを電子メールで送信する debugEmail() 関数を作成しました。アプリケーションからコードを実行すると、「条件 2 が機能した」ことがわかります。「何も機能しませんでした」の 1 秒前に呼び出されます。
これがどうなるかわかりません。If debugEmail("条件 2 が機能しました。"); $hasPaymentDatabaseAttached = true; が実行中です。その場合、これは実行されるべきではありません:
if (!$hasPaymentDatabaseAttached)
{
debugEmail("nothing worked.");
attachPaymentDatabase();
}
しかし、それは明らかにそうです。
ここで何が起こっているのですか?!?!?!?