简体   繁体   English

在同一PHP文件上使用具有不同归类的两个不同数据库

[英]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.

相关问题 连接到PHP中的两个不同的数据库? - Connect to two different databases in PHP? 在同一查询中访问不同服务器上的两个不同数据库 - access two different databases on different servers in the same query 在同一服务器上的两个不同文件夹中使用相同的PHP会话 - Use the same PHP session on two different folders on the same server 插入两个不同的数据库 - Insert into two different databases 是否可以在Symfony中为同一个捆绑包使用两个不同的数据库管理器? - Is it possible to use two diffrent document managers with different databases for the same bundle in Symfony? 将数据插入同一实例和同一用户的不同数据库的两个表中 - insert data into two tables of different databases on same instance and same user PHP PDO 是否对它支持的 12 个不同数据库使用相同的查询语法? - Does PHP PDO use the same query syntax for the 12 different databases it supports? 如何使用php连接两个不同服务器上的两个数据库 - How to Connect two databases on two different servers using php 用Laravel Eloquent加入同一台服务器上不同数据库中的两个MySQL表 - Join two MySQL tables in different databases on the same server with Laravel Eloquent 如何在同一台机器上同步不同MySQL数据库的两个表? - How to synchronize two tables of different MySQL databases on the same machine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM