<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nideaderedes &#187; charset</title>
	<atom:link href="http://nideaderedes.urlansoft.com/tag/charset/feed/" rel="self" type="application/rss+xml" />
	<link>http://nideaderedes.urlansoft.com</link>
	<description>Un blog hecho por mí y para mí</description>
	<lastBuildDate>Thu, 10 Jun 2010 18:46:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP: Cambiar el set de caracteres en una consulta MySQL</title>
		<link>http://nideaderedes.urlansoft.com/2008/08/12/php-cambiar-el-set-de-caracteres-en-una-consulta-mysql/</link>
		<comments>http://nideaderedes.urlansoft.com/2008/08/12/php-cambiar-el-set-de-caracteres-en-una-consulta-mysql/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 07:00:29 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[charset]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=347</guid>
		<description><![CDATA[Existe una función, que he de reconocer no conocía, que permite cambiar el set de caracteres (charset) cuando hacemos una consulta a MySQL.
Por ejemplo, si queremos asegurarnos que los datos que vamos a introducir en la base de datos van a estar en UTF-8 usaremos:

mysql_set_charset&#40;'utf8',$link&#41;;

(donde el parámetro $link, como en casi todas las funciones para [...]]]></description>
			<content:encoded><![CDATA[<p>Existe una función, que he de reconocer no conocía, que permite cambiar el set de caracteres (charset) cuando hacemos una consulta a MySQL.</p>
<p>Por ejemplo, si queremos asegurarnos que los datos que vamos a introducir en la base de datos van a estar en UTF-8 usaremos:</p>

<div class="wp_syntax"><div class="code"><pre class="php">mysql_set_charset<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8'</span><span style="color: #339933;">,</span><span style="color: #000033;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>(donde el parámetro $link, como en casi todas las funciones para mysql, es opcional).</p>
<p>Esta función se ha incorporado en la versión PHP 5 (5.0.7) y por lo visto también está disponible en la versión PHP 4 (a partir de la 4.1.13). En los <a href="http://es.php.net/manual/es/function.mysql-set-charset.php">comentarios de la documentación de PHP</a> han aportado este código que hace que mysql_set_charset funcione también en versiones anteriores de PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysql_set_charset'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">function</span> mysql_set_charset<span style="color: #009900;">&#40;</span><span style="color: #000033;">$charset</span><span style="color: #339933;">,</span> <span style="color: #000033;">$link_identifier</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$link_identifier</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SET NAMES &quot;'</span><span style="color: #339933;">.</span><span style="color: #000033;">$charset</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
             <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SET NAMES &quot;'</span><span style="color: #339933;">.</span><span style="color: #000033;">$charset</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000033;">$link_identifier</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2008/08/12/php-cambiar-el-set-de-caracteres-en-una-consulta-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
