[英]Use two different databases with different collations on same PHP file
I'm not entirely sure the title for this question is accurate, but it's my best guess. 我不确定这个问题的标题是否准确,但这是我的最佳猜测。 Here is my scenario in more details.
这是我的情况的更多详细信息。
I have a MediaWiki based website with content in Spanish. 我有一个基于MediaWiki的网站,其内容为西班牙语。 This site has its own data base.
该站点具有自己的数据库。 The special characters from the Spanish language render properly on the browser.
西班牙语的特殊字符会在浏览器上正确显示。
I have now added a PHP plugin to display popup messages. 我现在添加了一个PHP插件来显示弹出消息。 This plugin has its own database.
这个插件有自己的数据库。 I have stored special Spanish characters on this database successfully (I can see from phpMyAdmin the special characters are there), but when I pull data from this database to render on the user's browser the special characters are replaced by
我已成功在该数据库中存储了特殊的西班牙语字符(我从phpMyAdmin中可以看到特殊字符),但是当我从该数据库中提取数据以在用户浏览器上呈现这些特殊字符时,这些特殊字符将被替换为
You can see this issue live here http://es.wikiarquitectura.com/index.php/La_Ricarda_-_Casa_Gomis 您可以在此处实时看到此问题, 网址为http://es.wikiarquitectura.com/index.php/La_Ricarda_-_Casa_Gomis
Doing some reaseach I found somebody suggesting to add this to the file header('Content-Type: text/html; charset=ISO-8859-1');
做些努力,我发现有人建议将其添加到文件
header('Content-Type: text/html; charset=ISO-8859-1');
When I add the above line of code the popup text renders properly, but it's then the main content's special characters that are broken. 当我添加上面的代码行时,弹出文本将正确呈现,但是随后主要内容的特殊字符被破坏了。
Any idea how to get the content from both databases to render properly? 知道如何从两个数据库中获取内容以正确呈现吗?
I found the solution to my problem. 我找到了解决我问题的方法。
The way to fix it was to specify the charset that should be used when connecting to the second data base (the plugin's database). 解决该问题的方法是指定连接到第二个数据库(插件的数据库)时应使用的字符集。 See below
见下文
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
mysql_set_charset('utf8',$dbhandle);
The fourth line of the above did the trick :) 上面的第四行做到了:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.