问题
This is an example of the database connection I'm using with my PDO queries:
$dsn = "mysql:host=localhost;dbname=some_db;charset=utf8";
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn,'Username','Password', $opt);
How would I modify it if my database is located on www.mysite.com and I want to access the database from a different website?
回答1:
You need to open up port 3306 to accept connections.
$dsn = "mysql:host=mysite.com;dbname=some_db;charset=utf8";
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn,'Username','Password', $opt);
来源:https://stackoverflow.com/questions/23025821/pdo-database-connection-on-remote-website