我有一个表单,我想在 2 个数据库中提交表单数据。但问题是:两个数据库都在不同的服务器上。我是 mysql 新手,所以我不知道该怎么做。我在 php 工作。我正在与您分享我的代码,它无法正常工作。所以请检查一下:
$con = mysql_connect('differenthost','user1','pass1');
mysql_select_db('dbname1',$con);
$path = "misc/classified/".$submiturl;
mysql_query("insert into tablename1 (title,description,status,parent_id,path) values ('$submiturl','$submiturl','active','68','$path')") or die(mysql_error());
mysql_close($con);
mysql_connect('localhost','user2','pass2');
mysql_select_db('dbname2');
$check = mysql_query("select count(*) from tablename2 where userid = '".$_SESSION['userid']."' and datecreated = '$datecreated'") or die(mysql_error());
当我提交表单时出现此错误:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'differenthost' (25) in /home/class/public_html/microworker/submiturl.php on line 11
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/class/public_html/microworker/submiturl.php on line 12
Warning: mysql_query() [function.mysql-query]: Access denied for user 'user2'@'localhost' (using password: NO) in /home/class/public_html/microworker/submiturl.php on line 16
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/class/public_html/microworker/submiturl.php on line 16
Access denied for user 'user2'@'localhost' (using password: NO)
什么是正确的语法?