0

I have a main hosting account in goddady eg a.com

And I added an addon domain eg b.com

I created a database db_a, working with a.com correctly.

I created a database db_b, and trying to working with b.com, where can i configure it so that db_b is accessible by b.com as host=localhost?

SIDU
  • 2,258
  • 1
  • 12
  • 23

1 Answers1

0

After a big while of confusion and debugging, and I found out the reason / solution. But still not sure why Godaddy PDO has this issue.

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);

No error -- how confusing. And I test this, works:

<?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);

And now I come up with this solution, but not sure if it is Godaddy PDO bug?

<?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);

Conclusion:

It looks like Godaddy PDO does not use dbname, you need to manually run 'use dbname' after new PDO and before any other SQLs

SIDU
  • 2,258
  • 1
  • 12
  • 23