How to use a variable that returns a return

0

I'm pretty clumsy with the functions, and more with the use of return .

I have this code:

    public function addAuthor($autor, $nacimiento, $descripcion) {
        $sql = $this->db->prepare("INSERT INTO autores (Autor, Nacimiento, Descripcion) VALUES (:autor, :nacimiento, :descripcion)");
        $sql->execute(array(':autor'=>$autor, ':nacimiento'=>$nacimiento, ':descripcion'=>$descripcion));

        $lastID = $this->db->lastInsertId('IDAutor');

        return $lastID;
    }

I need to use the $lastID to be able to rename the photo with the id and then upload it.

this is the driver code:

$c->addAuthor($name, $nacimiento, $description);

How would I get the result of $lastID ? Should we call the function in another way? I am very lost with the issue of return . I tried to read in the PHP guide on the return but I still do not see the form.

    
asked by Charlie Clewer 20.06.2017 в 17:25
source

1 answer

2

So that the question is not open, if its function is correctly written and it returns the expected values, it would only have to assign the value to a variable X to use that value where it is required.

/* En la variable $id tendrá el valor devuelto por la función */
$id = $c->addAuthor($name, $nacimiento, $description);
    
answered by 20.06.2017 / 17:36
source