Shows how $query looks

Asked

Viewed 37 times

1

Guys I’ve seen it working somewhere but I can’t remember where. And the next I want to give a echo in my code and display how was the Mysql type Insert

$query1 = $conn->query("INSERT INTO dados1 VALUES (NULL, '".$nome."')");
        $id_dados1 = $id_doutor;
        echo "$query1";

and when I give the echo I need you to give me back something like

INSERT INTO dados1 VALUES (01, Joao)

so I know how the Insert

  • With Pdo? or Mysqli? $query1 has query return or false but not query string ...

  • Maybe that answer answer.

1 answer

0


Well have you thought about "generate" the query before running? Something like:

<?php
$sql1 = "INSERT INTO dados1 VALUES ('" . $nome . "');";
$query1 = $conn->query($sql1);
var_dump($query1);

echo $sql1; // Imprime SQL 1
?>

Because to print using the return itself you will have to change your class "$Conn" to generate this return.

As for the last ID inserted it only knows what it is after doing INSERT, and for that you can use a function or a new SELECT to pull this last ID as:

SELECT MAX(ID) FROM dados1

Or use a function like PHP has the function mysql_insert_id, it will be discontinued in future versions of PHP, but I don’t know what exists within its class "$Conn" then you can take it as a starting point to try to implement inside.

Browser other questions tagged

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