GoDaddy:如何将数据库添加到插件域

GoDaddy: How to add a database to an addon domain

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

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

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

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

纠结调试了半天,找到了原因/解决办法。但是还是不知道为什么 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[=28=之后手动运行 'use dbname' ] 和任何其他 SQL 之前