【问题标题】:GoDaddy: How to add a database to an addon domainGoDaddy:如何将数据库添加到插件域
【发布时间】:2017-04-03 11:39:10
【问题描述】:

我在 goddady 有一个主要的托管帐户,例如 a.com

我添加了一个插件域,例如 b.com

我创建了一个数据库 db_a,可以正确使用 a.com。

我创建了一个数据库 db_b,并尝试使用 b.com,我在哪里可以配置它以便 b.com 可以作为 host=localhost 访问 db_b?

【问题讨论】:

    标签: mysql database addon-domain


    【解决方案1】:

    经过一段时间的困惑和调试,我找到了原因/解决方案。但仍然不确定 Godaddy PDO 为什么会出现这个问题。

    PHP v5.4.45

    <?php
    $pdo = new PDO('mysql:localhost;dbname=mydb', $user, $pass);
    
    $sth = $pdo->prepare('select * from tab limit 1');
    $sth->execute();
    $row = $sth->fetchAll();
    echo '<pre>select * from test -- not working -- ';
    print_r($row);
    
    $sth = $pdo->prepare('select now()');
    $sth->execute();
    $row = $sth->fetchAll(PDO::FETCH_ASSOC);
    echo "\nselect now -- working -- ";
    print_r($row);
    
    $sth = $pdo->prepare('show databases');
    $sth->execute();
    $row = $sth->fetchAll(PDO::FETCH_ASSOC);
    echo "\nshow databases -- working -- ";
    print_r($row);
    
    $sth = $pdo->prepare('show tables');
    $sth->execute();
    $row = $sth->fetchAll(PDO::FETCH_ASSOC);
    echo "\nshow tables -- not working -- ";
    print_r($row);
    
    $sth = $pdo->prepare('show privileges');
    $sth->execute();
    $row = $sth->fetchAll(PDO::FETCH_ASSOC);
    echo "\nshow privileges -- working but not right -- ";
    print_r($row);
    
    $sth = $pdo->prepare('select * from information_schema.TABLES where TABLE_SCHEMA != \'information_schema\'');
    $sth->execute();
    $row = $sth->fetchAll(PDO::FETCH_ASSOC);
    echo "\nselect * from information_schema.TABLES -- working -- ";
    print_r($row);
    

    没有错误——多么令人困惑。我对此进行了测试,有效:

    <?php
    $pdo = new PDO('mysql:localhost;dbname=mydb', $user, $pass);
    
    $sth = $pdo->prepare('select * from mydb.tab limit 1');
    $sth->execute();
    $row = $sth->fetchAll();
    echo '<pre>select * from test -- working !!! -- ';
    print_r($row);
    

    现在我想出了这个解决方案,但不确定是不是 Godaddy PDO 错误?

    <?php
    $pdo = new PDO('mysql:localhost', $user, $pass);
    
    $sth = $pdo->prepare('use mydb');
    $sth->execute();
    
    $sth = $pdo->prepare('select * from tab limit 1');
    $sth->execute();
    $row = $sth->fetchAll();
    echo '<pre>select * from test -- working !!! -- ';
    print_r($row);
    

    结论:

    Godaddy PDO 似乎不使用 dbname,您需要在 new PDO 之后和任何其他 SQL 之前手动运行“use dbname

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 2018-12-27
      • 1970-01-01
      • 2023-03-17
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多