Visualizzazione 3 filoni di risposte
Visualizzazione 3 filoni di risposte
- Devi essere connesso per rispondere a questo topic.
Email: info@wpitaly.it
Home › Forum › Problemi Vari con WP › VEDERE DATI DI UN DATABASE ESTERNO
Buongiorno, che voi sappiate c’è la possibilità di inserire in una pagina di WP un elenco di dati, prelevati da una tabella di un DataBase ( in SQL ) che non è quello che sto utilizzando per creare il mio sito?
Spero di essere stata il più chiara possibile.
Grazie
si certo, ti crei un plugin ad hoc.
Ti posso fornire un paio di soluzioni.
1) Quella elegante: ti crei un tuo tema da assegnare alla pagina e nel codice php di questa inserisci il codice che legge i dati dal DB e li presenta a video;
2) Quella rapida: abiliti l’esecuzione diretta di codice nelle pagine del sito usando un plugin adatto( io ho scelto “Allow PHP in Posts and Pages”) ed utilizzi questo per inserire direttamente il codice php di interrrogazione( nel caso specifico del plugin citato basta inserire uno shortcode del tipo [php function=1] );
Per la cronaca io ho usato il secondo metodo, ma questo potrebbe comportare dei problemi di sicurezza.
Ciao,
Io ho utilizzato una soluzione molto semplice.
Ho creato uno shortcode nel function.php inserendo la query al di esterno
$mydb = new wpdb(‘username’,’password’,’database’,’localhost’);
$rows = $mydb->get_results(“select Name from my_table”);
echo “
foreach ($rows as $obj) :
echo “
“;
endforeach;
echo “
“;
Se vuoi i parametri di connessione li puoi dichiarare anche nel wp-config.php
Spero ti possa essere utile
Francesco
WPItaly - Copyright Creative Commons: CC BY-NC-SA 4.0