我有这个代码来根据登录的用户凭证启动db连接,问题是它在第一页(登录页)工作。如果我从登录页导航,它不会再次启动连接。我想知道怎么了?
如果我手动将用户的凭据添加到其中,它工作得很好,但是当它被动态添加时,如果我从登录页导航,它将无法再次启动。
当我在MAMP中读取PHP日志时,它总是显示这个错误。如果我从登录页导航,它会重新启动吗?
错误
[31-Aug-2018 21:51:11 Europe/Berlin] PHP Warning: fopen(send.txt): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle35/config.php on line 7
[31-Aug-2018 21:51:11 Europe/Berlin] PHP Warning: fread() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/moodle35/config.php on line 8
[31-Aug-2018 21:51:11 Europe/Berlin] PHP Notice: Undefined property: stdClass::$libdir in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33
[31-Aug-2018 21:51:11 Europe/Berlin] PHP Warning: require_once(/externallib.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33
[31-Aug-2018 21:51:11 Europe/Berlin] PHP Fatal error: require_once(): Failed opening required '/externallib.php' (include_path='.:/Applications/MAMP/bin/php/php7.0.15/lib/php') in /Applications/MAMP/htdocs/moodle35/lib/ajax/service.php on line 33
密码
//需要_一次('send.txt');
需要_once('/Applications/MAMP/htdocs/register/DBConnect.php');
$myFile = "send.txt";
$fh = fopen($myFile, 'r');
$myFileContents = fread($fh, 21);
//fclose($fh);
$mytrimmedvalue = trim($myFileContents);
unset($CFG);
global $CFG;
$CFG = new stdClass();
if ( $mytrimmedvalue != '' ) {
$database = new dbConnect();
$db = $database->openConnection();
$sql = "select * from ol_users where username = '$mytrimmedvalue'";
$user = $db->query($sql);
$result = $user->fetchAll(PDO::FETCH_ASSOC);
debug_to_console($result[0]['serverhosturl'] .'---------' .$mytrimmedvalue .'----------' .$result[0]['databasename']);
$CFG->dbtype = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost = $result[0]['serverhosturl'];
$CFG->dbname = $result[0]['databasename'];
$CFG->dbuser = $result[0]['serveruser'];
$CFG->dbpass = '111111ade';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbport' => '',
'dbsocket' => '1',
'dbcollation' => 'utf8mb4_unicode_ci',
);
$CFG->wwwroot = 'http://localhost:8888/moodle35';
// $CFG->wwwroot = 'http://192.168.0.199:8888/moodle35';
$CFG->dataroot = $result[0]['moodledataurl'];
$CFG->admin = 'admin';
$CFG->directorypermissions = 0777;
require_once(dirname(__FILE__) . '/lib/setup.php');
//$database->closeConnection();
}
function debug_to_console( $data ) {
$output = $data;
if ( is_array( $output ) )
$output = implode( ',', $output);
echo "<script>console.log( 'Debug Objects: " . $output . "' );</script>";
}