Created
February 21, 2012 15:59
-
-
Save ptn/1877139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('../wp-load.php'); | |
/* | |
* -------------------------------------------------------------------- | |
* SELECT | |
* -------------------------------------------------------------------- | |
/* | |
// IMPORTANTE: cuidado con los espacios y comas al escribir SQL a mano. | |
// Nota el espacio al final de la primera línea, sin eso no funcionaría: | |
$sql = "SELECT a, b, c FROM nombre_tabla "; | |
$sql .= "WHERE cond1 = val1 AND cond2 = val2"; | |
$resultados = $wpdb->get_results($sql); | |
foreach($resultados as $fila) { | |
// Las columnas seleccionadas via SELECT son accesibles con la sintaxis "->" | |
echo $fila->a; | |
echo $fila->b; | |
echo $fila->c; | |
} | |
/* | |
* -------------------------------------------------------------------- | |
* INSERT o UDPDATE | |
* -------------------------------------------------------------------- | |
/* | |
$sql = "INSERT INTO tabla (col1, col2, col3) "; | |
$sql .= "VALUES ('val1', $val2, 3)"; | |
$wpdb->query($sql); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment