so I have a simple code here that will insert a data and will return the last inserted id
. Here is my code:
function newUser($fname, $age) {
global $newUserLastID;
$conn = new PDO('mysql:host=localhost;dbname=myDB', 'root', '');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$data = $conn->prepare("INSERT INTO accounts (fname, age) VALUES (?, ?)");
$data->execute(array($fname, $age));
$newUserLastID = $conn->lastInsertId('accounts');
}
And what I wanted to do is to run the function and get the global variable like:
newUser('JohnDoe', '22');
$someVar = $newUserLastID;
My problem is whenever I run this code, my CLI
always crashes. Is there a way to fix this? I also get this on production server. I'm not getting any error besides this.
(by just running the function, my CLI crashes)