あなたが言及した2つの関数でdatabase.phpファイルを作成できます:function update()
とfunction insert()
.
次に、次のように、phpinclude
を使用して、database.php ファイルを他の 2 つのファイルに含めます。
insert.php
include_once('database.php');
insert(your data comes here);
変更.php
include_once('database.php');
update(your data comes here);
モデルがあるデータベース層を作成し、これにクラスのインスタンスを使用する必要があります。次に、database.php を他のスクリプトに含め、db オブジェクトをインスタンス化し、メソッドを呼び出します。このようなもの:
データベース.php
class MyDatabaseThingy
{
/* rest of your code */
public function update(data) {your code here}
public function insert(data) {your code here}
/* rest of your code */
}
insert.php
include_once(database.php);
$dbObj = new MyDatabaseThingy();
/* make sure you have the connection and so on */
$dbObj->insert(your data);
変更.php
include_once(database.php);
$dbObj = new MyDatabaseThingy();
/* make sure you have the connection and so on */
$dbObj->update(your data);