PDO: Database connection on remote website

元气小坏坏 提交于 2020-01-30 03:31:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!