代码之家  ›  专栏  ›  技术社区  ›  Mrco

PHP XAMPP配置[关闭]

  •  -2
  • Mrco  · 技术社区  · 1 年前

    我尝试将我的php网站与XAMPP服务器连接,这样我就可以访问我的MySQL数据库。任何关于配置应该是什么样子的想法,因为我很纠结于这个。

    我试着做了一个配置,但没有真正奏效。我会在下面发布我当前的配置:

    <?php
        try {
            global $con;
            $server = 'localhost:3307';
            $user = 'root';
            $schema = '';
    
            $con = new PDO('mysql:host='.$server.';schema = '.$schema.';charset=utf8', $user);
            $con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
        } catch(Exception $e) {
            echo $e->getCode().': '.$e->getMessage();
        }
    
    1 回复  |  直到 1 年前
        1
  •  0
  •   Uwe Hintersteiner    1 年前

    我认为在用户之后缺少密码参数。不幸的是,您没有提供错误,但可能您的错误是空的$schema参数。如果你不把模式的名称放在那里,你就不会连接到一个模式,所以你必须使用<使用[架构的名称]>以连接到它。

    <?php
     try
     {
         global $con;
         $server = 'localhost:3307';
         $user = 'root';
         $pwd = '';
         $schema = '';
    
         $con = new PDO('mysql:host='.$server.';schema = '.$schema.';charset=utf8', $user,$pwd);
         $con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    }
    catch(Exception $e)
    {
     echo $e->getCode().': '.$e->getMessage();
    }