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

时间:2017-04-03 11:39:11

标签: mysql database addon-domain

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

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

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

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

1 个答案:

答案 0 :(得分:0)

经过一段时间的混乱和调试,我发现了原因/解决方案。但仍然不确定为什么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,您需要手动运行&#39; 使用dbname &#39;在新PDO 之后和任何其他SQL之前