The symptoms of a bad mass air flow sensor can include the engine starting and running somewhat OK for a few seconds then stopping, despite throttle position. Depending on the vehicle, one may need to order the tube the sensor protrudes into as a calibrated set with the sensor. Be aware that the necessary gasket(s) if any may not be included. Try to internet search or call a shop to see if a gasket is required. Or, simply check what’s on the old sensor.
Don’t forget to put in a new air cleaner at the same time, and to wipe out any dust from the air box.
A diagnostic technique that often works is to unplug the sensor and the car may run, but in a failsafe mode that’s fuel-mixture rich. The car may consume excess fuel and make a strong smell from the exhaust. I would avoid driving the car in this state, just use it for several seconds to see if plugging the sensor back in stops the engine.