<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[passaggio da procedurale a oop]]></title><description><![CDATA[<p dir="auto">Buongiorno a tutti,</p>
<p dir="auto">sono un appassionato dilettante di php, quel poco che ho fatto l'ho scritto sempre con php procedurale,<br />
ora vorrei passare a php ad oggetti, per questo vorrei una delucidazione:</p>
<p dir="auto">prima scrivevo:</p>
<pre><code class="language-php">function utenti(){
$array_utenti = array();
$query_utenti = mysql_query("SELECT utenti.nome, utenti.cognome, utenti.foto, utenti.email, siti.url FROM utenti INNER JOIN utente_sito ON utenti.id = utente_sito.utente INNER JOIN siti ON siti.id = utente_sito.sito ORDER BY siti.url ASC");
while ($row = mysql_fetch_assoc($query_utenti)): $array_utenti[] = array(
"nome" =&gt; $row['nome'],
"cognome" =&gt; $row['cognome'],
"foto" =&gt; $row['foto'],
"email" =&gt; $row['email'],
"url" =&gt; $row['url']
);
endwhile;
$utenti = array();
foreach ($array_utenti as $utente) {
$utenti[] = array(
"nome" =&gt; $utente['nome'],
"cognome" =&gt; $utente['cognome'],
"foto" =&gt; $utente['foto'],
"email" =&gt; $utente['email'],
"url" =&gt; $utente['url']
);
}
return $utenti;
}
$utenti = utenti();
foreach ($utenti as $utente) {
echo $utente['url']."&lt;br /&gt;";
echo $utente['nome']."&lt;br /&gt;";
echo $utente['cognome']."&lt;br /&gt;";
echo $utente['foto']."&lt;br /&gt;";
echo $utente['email']."&lt;hr&gt;";
}
</code></pre>
<p dir="auto">ora scrivo:</p>
<pre><code class="language-php">class Editor{
public function utenti(){
$array_utenti = array();
$query_utenti = mysql_query("SELECT utenti.nome, utenti.cognome, utenti.foto, utenti.email, siti.url FROM utenti INNER JOIN utente_sito ON utenti.id = utente_sito.utente INNER JOIN siti ON siti.id = utente_sito.sito ORDER BY siti.url ASC");
while ($row = mysql_fetch_assoc($query_utenti)): $array_utenti[] = array(
"nome" =&gt; $row['nome'],
"cognome" =&gt; $row['cognome'],
"foto" =&gt; $row['foto'],
"email" =&gt; $row['email'],
"url" =&gt; $row['url']
);
endwhile;
$utenti = array();
foreach ($array_utenti as $utente) {
$utenti[] = array(
"nome" =&gt; $utente['nome'],
"cognome" =&gt; $utente['cognome'],
"foto" =&gt; $utente['foto'],
"email" =&gt; $utente['email'],
"url" =&gt; $utente['url']
);
}
return $utenti;
}
}
$class_editor = new Editor();
$utenti = $class_editor-&gt;utenti();
foreach ($utenti as $utente) {
echo $utente['url']."&lt;br /&gt;";
echo $utente['nome']."&lt;br /&gt;";        
echo $utente['cognome']."&lt;br /&gt;";
echo $utente['foto']."&lt;br /&gt;";
echo $utente['email']."&lt;hr&gt;";
}
</code></pre>
<p dir="auto">secondo voi è corretto?</p>
]]></description><link>https://dev.connect.gt/topic/225443/passaggio-da-procedurale-a-oop</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 22:33:44 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/225443.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Sep 2016 15:32:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to passaggio da procedurale a oop on Sun, 30 Oct 2016 20:13:41 GMT]]></title><description><![CDATA[<p dir="auto">Perchè?</p>
]]></description><link>https://dev.connect.gt/post/1227383</link><guid isPermaLink="true">https://dev.connect.gt/post/1227383</guid><dc:creator><![CDATA[enricocarli]]></dc:creator><pubDate>Sun, 30 Oct 2016 20:13:41 GMT</pubDate></item><item><title><![CDATA[Reply to passaggio da procedurale a oop on Sun, 30 Oct 2016 17:26:57 GMT]]></title><description><![CDATA[<p dir="auto">Posso permettermi un consiglio? Usate gli heredocs!</p>
]]></description><link>https://dev.connect.gt/post/1227379</link><guid isPermaLink="true">https://dev.connect.gt/post/1227379</guid><dc:creator><![CDATA[enigma]]></dc:creator><pubDate>Sun, 30 Oct 2016 17:26:57 GMT</pubDate></item><item><title><![CDATA[Reply to passaggio da procedurale a oop on Sat, 29 Oct 2016 09:43:01 GMT]]></title><description><![CDATA[<p dir="auto">Ciao Jhon92,<br />
ho una domanda, ma perchè estrai i dati con un metodo, e con un altro li stampi? Sicurezza?</p>
<p dir="auto">sto provando a scrivere delle classi, posto il codice così mi dici cosa ne pensei.</p>
<p dir="auto">ciao e grazie!</p>
<pre><code class="language-php">&lt;?php
    class Examples{
        private $db;        

        public function __construct(){
            $this-&gt;db = new mysqli('localhost', 'root', 'hal9000', 'examples');
        }

        public function get_actors(){
            $actors = array();
            $query = $this-&gt;db-&gt;query('SELECT * FROM actor LIMIT 10');
            while ($row = $query-&gt;fetch_array(MYSQLI_ASSOC)){
                $actors[] = array(
                    "id" =&gt; $row['actor_id'],
                    "fullname" =&gt; $row['fullname']
                );
            }
            return $actors;
        }

        public function __destruct(){
            mysqli_close($this-&gt;db);
        }
    }

    class Codeigniter{
        private $db;

        public function __construct(){
            $this-&gt;db = new mysqli('localhost', 'root', 'hal9000', 'myapp_moto');
        }

        public function get_actors(){
            $actors = array();
            $query = $this-&gt;db-&gt;query('SELECT * FROM articoli LIMIT 10');
            while ($row = $query-&gt;fetch_array(MYSQLI_ASSOC)){
                $actors[] = array(
                    "id" =&gt; $row['id'],
                    "titolo" =&gt; $row['titolo']
                );
            }
            return $actors;
        }

        public function __destruct(){
            mysqli_close($this-&gt;db);
        }
    }

    $attori = new Examples();
    echo "&lt;pre&gt;";
    print_r($attori-&gt;get_actors());
    echo "&lt;/pre&gt;";

    $news = new Codeigniter();
    echo "&lt;pre&gt;";
    print_r($news-&gt;get_actors());  
    echo "&lt;/pre&gt;";    
?&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/post/1227382</link><guid isPermaLink="true">https://dev.connect.gt/post/1227382</guid><dc:creator><![CDATA[enricocarli]]></dc:creator><pubDate>Sat, 29 Oct 2016 09:43:01 GMT</pubDate></item><item><title><![CDATA[Reply to passaggio da procedurale a oop on Fri, 14 Oct 2016 18:38:14 GMT]]></title><description><![CDATA[<p dir="auto">Grazie mille x la risposta, scusa il ritardo ma non ho ricevuto la notifica. Do un occhio al codice e se ho dubbi ti chiedo. Buon week end e grazie ancora!</p>
]]></description><link>https://dev.connect.gt/post/1227381</link><guid isPermaLink="true">https://dev.connect.gt/post/1227381</guid><dc:creator><![CDATA[enricocarli]]></dc:creator><pubDate>Fri, 14 Oct 2016 18:38:14 GMT</pubDate></item><item><title><![CDATA[Reply to passaggio da procedurale a oop on Fri, 16 Sep 2016 16:25:12 GMT]]></title><description><![CDATA[<pre><code class="language-php">class Editor
{
    private $db;
    protected $array_utenti = array();

    public function __construct()
    {
        $this-&gt;db = new mysqli('localhost', 'root', '', 'prova');
    }

    protected function utenti()
    {
        $query_utenti = $this-&gt;db-&gt;query('SELECT utenti.nome, utenti.cognome, utenti.foto, utenti.email, siti.url FROM utenti INNER JOIN utente_sito ON utenti.id = utente_sito.utente INNER JOIN siti ON siti.id = utente_sito.sito ORDER BY siti.url ASC');
        while ($row = $query_utenti-&gt;fetch_array(MYSQLI_ASSOC))
        {
            $this-&gt;array_utenti[] = array(
                "nome" =&gt; $row['nome'],
                "cognome" =&gt; $row['cognome'],
                "foto" =&gt; $row['foto'],
                "email" =&gt; $row['email'],
                "url" =&gt; $row['url']
            );
        }
    }

    public function getUtenti()
    {
        $this-&gt;utenti();
        print "&lt;pre&gt;".print_r($this-&gt;array_utenti, true)."&lt;/pre&gt;";
        foreach($this-&gt;array_utenti as $utente)
        {
            echo $utente['url']."&lt;br /&gt;";
            echo $utente['nome']."&lt;br /&gt;";        
            echo $utente['cognome']."&lt;br /&gt;";
            echo $utente['foto']."&lt;br /&gt;";
            echo $utente['email']."&lt;hr&gt;";
        }
    }
}

$editor = new Editor();
$editor-&gt;getUtenti();
</code></pre>
]]></description><link>https://dev.connect.gt/post/1227384</link><guid isPermaLink="true">https://dev.connect.gt/post/1227384</guid><dc:creator><![CDATA[jhon92]]></dc:creator><pubDate>Fri, 16 Sep 2016 16:25:12 GMT</pubDate></item></channel></rss>