Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Moodle数据库连接在本地数据库中失败_Php_Mysql_Moodle - Fatal编程技术网

Php Moodle数据库连接在本地数据库中失败

Php Moodle数据库连接在本地数据库中失败,php,mysql,moodle,Php,Mysql,Moodle,我正试图在本地安装一个现有的Moodle应用程序来开发一个子主题,但在配置config.php后会出现以下消息。我不能意识到这个错误。这是我的档案: <?php unset($CFG); // Ignore this line global $CFG; // This is necessary here for PHPUnit execution $CFG = new stdClass(); $CFG->dbtype = 'mysqli'; // 'mysqli'

我正试图在本地安装一个现有的Moodle应用程序来开发一个子主题,但在配置
config.php
后会出现以下消息。我不能意识到这个错误。这是我的档案:

<?php
unset($CFG);  // Ignore this line
global $CFG;  // This is necessary here for PHPUnit execution
$CFG = new stdClass();
$CFG->dbtype    = 'mysqli';      // 'mysqli', 'mariadb', 'mysqli', 'mssql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native';     // 'native' only at the moment
$CFG->dbhost    = 'localhost';  // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname    = '(name)';     // database name, eg moodle
$CFG->dbuser    = '(same as above)';   // your database username
$CFG->dbpass    = '(pass)';   // your database password
$CFG->prefix    = 'pztp_';       // prefix to use for all table names
$CFG->dboptions = array(
    'dbpersist' => false,       // should persistent database connections be
                                //  used? set to 'false' for the most stable
                                //  setting, 'true' can improve performance
                                //  sometimes
    'dbsocket'  => false,       // should connection via UNIX socket be used?
                                //  if you set it to 'true' or custom path
                                //  here set dbhost to 'localhost',
                                //  (please note mysql is always using socket
                                //  if dbhost is 'localhost' - if you need
                                //  local port connection use '127.0.0.1')
    'dbport'    => '3306',          // the TCP port number to use when connecting
                                //  to the server. keep empty string for the
                                //  default port
);
$CFG->wwwroot   = 'http://'.$_SERVER['SERVER_NAME'];
$CFG->dataroot  = 'C:/wamp64/www/example/data';
$CFG->directorypermissions = 02777;
$CFG->admin = 'admin';
require_once(dirname(__FILE__) . '/lib/setup.php'); // Do not edit

可以尝试在Moodle根文件夹中创建一个测试PHP文件,以测试连接,查看其Moodle还是数据库

<?php

$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport);

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}

echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close();

谢谢!我不知道它是否有效,因为在你发布它的时候我并不需要它,但我真的很感谢你花时间解决我的问题。多谢各位!