以下のコードを使用してデータベースに常時接続するcron関数のいくつかが突然失敗し始めた問題は何ですか?エラー:mssql_connect():サーバーに接続できません:
DBに接続できないようです。資格は良いですが、変更されませんでした。 TestConnectは、私のDBに接続したいと呼ばれるクラスです。私はこれを次のように使用します:
$test = new \TestConnect(true);
これでクラスファイルが見つかりましたが、私が理解する限りは動作しています。
class TestConnect
{
private $_server = 'test';
private $_username = 'test';
private $_password = 'password';
private $_database = 'database';
private $_query = null;
private $_handle = null;
private $_handle_db = null;
private $_result = null;
public function __construct($connect = null, $query = null)
{
if ($connect)
{
$this->connect();
}
if ($query)
{
$this->query($query);
}
}
public function connect()
{
ini_set('memory_limit','1024M');
putenv("FREETDSCONF=/etc/freetds.conf");
if ($this->_handle)
{
return $this->_handle;
}
else
{
if (! $this->_handle = mssql_connect($this->_server, $this->_username, $this->_password))
{
throw new Exception($this->get_error_message());
}
if (! $this->_handle_db = mssql_select_db($this->_database, $this->_handle))
{
throw new Exception($this->get_error_message());
}
}
}
}
ここで最も興味深いのは、$ test = new \ TestConnect(true);ある種の関数に呼び出され、別の関数から呼び出すと、うまくいくように見えます。しかし、私が$ test = new \ TestConnect(true)を呼び出すと、非常に同じ機能から - それは動作していません。
それはこのように働いています:
private function getDatabase(){
$test = new \TestConnect(true);
$test->query("SELECT id as id FROM table");
return $test->fetch_assoc($trim = true);
}
そして、私は次のようにこの関数を呼び出す:接続工事こう
$users = self::getDatabase();
と私はすべてのデータを取得します。しかし、関数を使わずにコードを使用すれば、機能しません。これはどのように可能ですか?
最近PHP7にアップグレードしましたか? – argoden
いいえ、バージョンは5.4です。 – The50
詳細情報を更新しました。 – The50