<?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>Symfony-IT &#187; mysql</title>
	<atom:link href="http://www.symfony.it/categoria/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.symfony.it</link>
	<description>Just another Symfony Framework weblog</description>
	<lastBuildDate>Mon, 26 Jul 2010 09:23:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Confrontare due campi della stessa tabella con Propel</title>
		<link>http://www.symfony.it/articoli/8/confrontare-due-campi-della-stessa-tabella-con-propel/</link>
		<comments>http://www.symfony.it/articoli/8/confrontare-due-campi-della-stessa-tabella-con-propel/#comments</comments>
		<pubDate>Thu, 19 Jul 2007 13:57:21 +0000</pubDate>
		<dc:creator>kea</dc:creator>
				<category><![CDATA[hacks]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.symfony.it/articoli/8/confrontare-due-campi-della-stessa-tabella-con-propel/</guid>
		<description><![CDATA[Con il criteria di Propel non è possibile ancora confrontare due campi della stessa tabella ma solo il campo con un valore. Questa feature sarà probabilmente implementata nella versione 2.0. Nel frattempo vi propongo questo trick per confrontare tra loro i campi Campo1 e Campo2 della tabella Tabella PLAIN TEXT CODE: $c = new Criteria&#40;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Con il criteria di Propel non è possibile ancora  confrontare due campi della stessa tabella ma solo il campo con un valore.  Questa feature sarà probabilmente implementata nella versione 2.0.</p>
<p>Nel frattempo vi propongo questo trick per confrontare tra loro i campi Campo1 e Campo2 della tabella Tabella</p>
<div class="igBar"><span id="lcode-2"><a href="#" onclick="javascript:showPlainTxt('code-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-2">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$c = new Criteria<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$c-&gt;<span style="">add</span><span style="color:#006600; font-weight:bold;">&#40;</span>Tabella.<span style="">Campo1</span>, Tabella.<span style="">Campo1</span>.<span style="color:#CC0000;">' = '</span>.<span style="">Tabella</span>.<span style="">Campo2</span>, Criteria:CUSTOM<span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Naturalmente al posto di ".' = ' ." potere inserire l'operatore che vi serve (=, &lt;&gt;, !=, &lt;, &gt;, etc.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/8/confrontare-due-campi-della-stessa-tabella-con-propel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Importare un file CSV all&#8217;interno del database</title>
		<link>http://www.symfony.it/articoli/6/importare-un-file-csv-allinterno-del-database/</link>
		<comments>http://www.symfony.it/articoli/6/importare-un-file-csv-allinterno-del-database/#comments</comments>
		<pubDate>Wed, 04 Jul 2007 20:46:45 +0000</pubDate>
		<dc:creator>fullo</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.symfony.it/articoli/6/importare-un-file-csv-allinterno-del-database/</guid>
		<description><![CDATA[Spesso risulta necessario importare grosse moli di dati direttamente nel database passando da una form. Nel caso di grosse mole di dati, l'utilizzo di oggetti rischia di sovraccaricare il sistema pertanto l'utilizzo delle funzioni native del DBMS (nel caso di MySQL) spesso si traduce in una ottima soluzione. Supponiamo quindi di aver caricato tramite form [...]]]></description>
			<content:encoded><![CDATA[<p>Spesso risulta necessario importare grosse moli di dati direttamente nel database passando da una form. </p>
<p>Nel caso di grosse mole di dati, l'utilizzo di oggetti rischia di sovraccaricare il sistema pertanto l'utilizzo delle funzioni native del DBMS (nel <a href="http://dev.mysql.com/doc/refman/5.0/en/load-data.html">caso di MySQL</a>) spesso si traduce in una ottima soluzione.</p>
<p><span id="more-6"></span></p>
<p>Supponiamo quindi di aver caricato tramite form un file CVS nel sistema ecco come dovrà essere il metodo da inserire nella <code>actions.class.php</code> per gestire l'importazione. </p>
<div class="igBar"><span id="lcode-10"><a href="#" onclick="javascript:showPlainTxt('code-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-10">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public function executeImport<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; if <span style="color:#006600; font-weight:bold;">&#40;</span>$this-&gt;<span style="">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="">hasFiles</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $filename = date<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'Ymd'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0000;">'-'</span>.$tipo.<span style="color:#CC0000;">'-filename.csv'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;<span style="">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="">moveFile</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'file_import'</span>, sfConfig::<span style="">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'sf_upload_dir'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0000;">'/'</span>.$filename<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// elimino tutti i vecchi dati</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; TabellaPeer::<span style="">doDeleteAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// inizializzo la gestione del db&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $databaseManager = new sfDatabaseManager<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $databaseManager-&gt;<span style="">initialize</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp;&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $connection = Propel::<span style="">getConnection</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// creo la query di import del file usando la sintassi di LOAD FILE di MySQL</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $query = <span style="color:#CC0000;">'LOAD DATA INFILE &quot;'</span>.<span style="">sfConfig</span>::<span style="">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'sf_upload_dir'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0000;">'/'</span>.$filename.<span style="color:#CC0000;">'&quot; '</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $query.= <span style="color:#CC0000;">' INTO TABLE '</span>.<span style="">TabellaPeer</span>::<span style="">TABLE_NAME</span> .<span style="color:#CC0000;">' FIELDS TERMINATED BY &quot;|&quot; ENCLOSED BY &quot;&quot; LINES TERMINATED BY &quot;<span style="color:#000099; font-weight:bold;">\n</span>&quot; '</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $query.= <span style="color:#CC0000;">'(campo1,campo2,campo3) SET campo4 = &quot;costante&quot;'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $statement = $connection-&gt;<span style="">prepareStatement</span><span style="color:#006600; font-weight:bold;">&#40;</span>$query<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $resultset = $statement-&gt;<span style="">executeQuery</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Analizziamo passo passo cosa facciamo nel metodo</p>
<div class="igBar"><span id="lcode-11"><a href="#" onclick="javascript:showPlainTxt('code-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-11">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#40;</span>$this-&gt;<span style="">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="">hasFiles</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Innanzitutto verifichiamo che il file sia stato caricato correttamente, in realtà potremmo inserire ulteriori controlli come ad esempio che i META-TYPE corrispondano a quelli di un file CSV, ma per ora soprassediamo.</p>
<div class="igBar"><span id="lcode-12"><a href="#" onclick="javascript:showPlainTxt('code-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-12">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$filename = date<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'Ymd'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0000;">'-'</span>.$tipo.<span style="color:#CC0000;">'-filename.csv'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$this-&gt;<span style="">getRequest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>-&gt;<span style="">moveFile</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'file_import'</span>, sfConfig::<span style="">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'sf_upload_dir'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0000;">'/'</span>.$filename<span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Generiamo il nome del file e lo spostiamo nella directory di upload impostata nel file di configurazione della nostra applicazione</p>
<div class="igBar"><span id="lcode-13"><a href="#" onclick="javascript:showPlainTxt('code-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-13">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// elimino tutti i vecchi dati</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">TabellaPeer::<span style="">doDeleteAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Questo passaggio è opzionale, facendo così vengono cancellati tutti i vecchi dati relativi alla tabella su cui vogliamo lavorare, utile nel caso di aggiornamenti massicci (ad esempio da gestionali), meno utile se importiamo sempre nuovi dati.</p>
<div class="igBar"><span id="lcode-14"><a href="#" onclick="javascript:showPlainTxt('code-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-14">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$databaseManager = new sfDatabaseManager<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$databaseManager-&gt;<span style="">initialize</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp;&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$connection = Propel::<span style="">getConnection</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Inizializzamo la connessione al database usando Propel e prepariamo la query.</p>
<div class="igBar"><span id="lcode-15"><a href="#" onclick="javascript:showPlainTxt('code-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-15">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// creo la query di import del file usando la sintassi di LOAD FILE di MySQL</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$query = <span style="color:#CC0000;">'LOAD DATA INFILE &quot;'</span>.<span style="">sfConfig</span>::<span style="">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'sf_upload_dir'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0000;">'/'</span>.$filename.<span style="color:#CC0000;">'&quot; '</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$query.= <span style="color:#CC0000;">' INTO TABLE '</span>.<span style="">TabellaPeer</span>::<span style="">TABLE_NAME</span> .<span style="color:#CC0000;">' FIELDS TERMINATED BY &quot;|&quot; ENCLOSED BY &quot;&quot; LINES TERMINATED BY &quot;<span style="color:#000099; font-weight:bold;">\n</span>&quot; '</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$query.= <span style="color:#CC0000;">'(campo1,campo2,campo3) SET campo4 = &quot;costante&quot;'</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Qui generiamo la query che verrà eseguita su MySQL. Utilizzando il metodo <code>LOAD</code> carichiamo il file creato poco prima successivamente andiamo ad indicare il nome della tabella su cui vogliamo lavorare, il separatore tra un campo e l'altro (ad esempio | ), il carattere all'interno del quale il campo è racchiuso (alcuni file CSV ad esempio usano <code>'</code> o <code>"</code>), ed il carattere di fine linea (nel nostro caso l'andata a capo).</p>
<p>Infine nell'ultima riga della query andiamo ad indicare a cosa corrispondono i campi del CSV rispetto a quelli della tabella. E' interessante notare che è possibile anche <em>forzare</em> una variabile nel caso che quest'ultima non sia presente nel file.</p>
<div class="igBar"><span id="lcode-16"><a href="#" onclick="javascript:showPlainTxt('code-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-16">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$statement = $connection-&gt;<span style="">prepareStatement</span><span style="color:#006600; font-weight:bold;">&#40;</span>$query<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$resultset = $statement-&gt;<span style="">executeQuery</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Infine andiamo ad inserire la query nel metodo <code>prepareStatement()</code> che si occupa di tradurla per CREOLE e di eseguirla successivamente.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.symfony.it/articoli/6/importare-un-file-csv-allinterno-del-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->