私はconnections.phpでmysqli接続を宣言します。私は$ this->接続の代わりにを宣言する$私は1つのファイル内の各機能を分離したいからです。
<?php
$this->connection = mysqli_connect("localhost","root","","itdforum");
if(mysqli_connect_errno){
echo "Failed to connect to MYSQL: " . mysqli_connect_error();
}
?>
私は、誰もがそれを修正する方法を知っている
Using $this when not in object context in localhost\connections.php
以下のように他の機能
<?php
include("connections.php");
function getSome(){
$get_some = "SELECT * FROM table"
$run_some = mysqli_query($this->connection, $get_some);
}
?>
が、エラーショーで$この接続を使用しようとしていますか?または私はちょうど1つのPHPファイルにすべての関数を追加しますか?ありがとう。
はmillinonの回答に同意:あなたが使用したい場合は、「$これを」あなたはラッピングを作成する必要がありますクラス。おそらく、それはデータベース全体の相互作用を管理するユーティリティタイプのクラスであろう。 $ GLOBALS ['database']を使用して、接続ポインタを$ thisではなく格納することもできます。 –