简体   繁体   English

我如何将数据从数据库(My Sql)导入到另一个网站

[英]how i can Import data from Database ( My Sql) to another website

I need to show data from another website in my website, i had control panel for tow site but i need it dynamic way to connect them 我需要在我的网站上显示另一个网站的数据,我有两个网站的控制面板,但是我需要它以动态方式连接它们

   website 1         website 2 
    *****              *****
    * A * <<<< =Data== * B *
    *****              *****

so i write 所以我写

$link = @mysql_connect("Ip Addres to another website","username for mysql 2","passowrd 2 ")or die("Couldn't make connection.");

    @mysql_select_db("qatarlab_test",$link)or die("Couldn't select database");

    $factorRes = @mysql_query("SELECT count(id) FROM `factor` ");

    $factorRow = @mysql_fetch_array($factorRes);        

    echo  $factorRow[0];

but nothing happen 但什么都没发生

Hi Please try code given below, 嗨,请尝试下面给出的代码,

$link = @mysql_connect("Ip Addres to another website","username for mysql 2","passowrd 2 ")or die("Couldn't make connection.") or die(mysql_error());

mysql_select_db("qatarlab_test",$link)or die("Couldn't select database", $link) or die(mysql_error());

$factorRes = @mysql_query("SELECT count(id) FROM `factor` " , $link) or die(mysql_error());

$factorRow = @mysql_fetch_array($factorRes);        

echo "<pre>";
print_r($factorRow);
echo "</pre>";

Here $link will be for specific database connection and die(mysql_error()) for if any error in or query or database connection. 这里$link将用于特定的数据库连接,而die(mysql_error())用于查询或数据库连接中的任何错误。

thanks 谢谢

In your first line: mysql_connect you are passing the IP Address and Username for connecting the DB. 在第一行:mysql_connect中,您正在传递用于连接数据库的IP地址和用户名。

Make sure that the user has the privilege to connect to the DB remotely (ie via a machine other than the Localhost). 确保用户有权远程(即通过本地主机以外的计算机)连接到数据库。 In general, when a user is added in the DB its default access is for the localhost. 通常,将用户添加到数据库中后,其默认访问权限为本地主机。 Check out this link: http://dev.mysql.com/doc/refman/5.1/en/adding-users.html 查看此链接: http : //dev.mysql.com/doc/refman/5.1/en/adding-users.html

You basically need to add user using: CREATE USER 'admin'@'IP Address of Website 1'; 您基本上需要使用以下方式添加用户:CREATE USER'admin'@'网站1的IP地址'; All the CPanel's have this provision in their interface as well. 所有CPanel的界面中也都有此规定。

Firstly, you must enable remote database connection in the original site so that the new site can connect to it. 首先,必须在原始站点中启用远程数据库连接,以便新站点可以连接到它。 you can do this in the control panel->Database(Remote Database Connection) of the original site. 您可以在原始站点的控制面板->数据库(远程数据库连接)中执行此操作。

You could specify the IP or domain of the new site to that it allows only the new site to connect or you could just add wildcard (%) to allow any external connection to the database. 您可以指定新站点的IP或域,使其仅允许新站点进行连接,也可以添加通配符(%)以允许任何外部连接到数据库。

when this is done, run ur query again. 完成此操作后,再次运行ur查询。

hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM