Show how the $ query got

1

People already saw this running somewhere but I can not remember where. and the following I want to give a echo in my code and to display as it was the insert in Mysql type

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

And when I give echo I need something like this to return

INSERT INTO dados1 VALUES (01, Joao)

To let me know how the insert got

    
asked by anonymous 11.05.2016 / 05:28

1 answer

0

Well have you thought about "generating" the query before executing? Something like:

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

echo $sql1; // Imprime SQL 1
?>

Even because to print using the return itself you will have to change your "$ conn" class to generate this return.

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

SELECT MAX(ID) FROM dados1

Or use a function like said PHP has the function mysql_insert_id , it goes be discontinued in future versions of PHP, but I do not know what exists within your "$ conn" class so you can take it as a starting point to try to implement in.

    
11.05.2016 / 07:00