Skip to content

Instantly share code, notes, and snippets.

@ptn
Created February 21, 2012 15:59
Show Gist options
  • Save ptn/1877139 to your computer and use it in GitHub Desktop.
Save ptn/1877139 to your computer and use it in GitHub Desktop.
<?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