Save table field to a php variable

Asked

Viewed 32 times

-2

Good afternoon, guys, how are you? I have a basic doubt, but I think you could help me, as I could save the result of a field within a PHP variable?

$sql = "SELECT ped_liberado FROM tb_pedido WHERE ped_id = 1267570";

This is my SELECT, I would like to save the value of the 'ped_liberated' field, as I could save it within a variable?

Thanks in advance

2 answers

1


Let’s say you’re using postgresql:

$sql = "SELECT ped_liberado FROM tb_pedido WHERE ped_id = 1267570";
$resultado = pg_query($sql);
$ped_liberado = pg_fetch_result($resultado,0,"ped_liberado ");
  • 1

    Okay, thank you very much Gabriel, I’m doing several tests here, strong hug.

1

If you’re using PDO, it would go something like this:

$conn = funcao_de_conexao();
$sql = "SELECT ped_liberado FROM tb_pedido WHERE ped_id = 1267570";
$query = $conn->prepare($sql);
$result = $query->execute();
$id_pedido = $query->fetchColumn(); // vai trazer o único resultado e armazenar na variavel
  • Thank you so much Andre for the help, I’m doing several tests here to see which one I end up using, strong hug.

  • You’re welcome and good luck, anything, you can ask!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.