The Carthaginians did use elephants in their army, but those beasts were difficult to handle. Here's what Livy says about their drivers:
More elephants were killed by their drivers than by the enemy. They had a carpenter's chisel and a mallet, and when the maddened beasts rushed among their own side the driver placed the chisel between the ears just where the head is joined to the neck and drove it home with all his might. This was the quickest method that had been discovered of putting these huge animals to death when there was no hope of controlling them, and Hasdrubal was the first to introduce it. -- Livy, XXVII, 49
Also, in Salammbô, we read:
He [Hamilcar] organised a phalanx of seventy-two elephants with those which had returned from Utica, and others which were private property, and rendered them formidable. He armed their drivers with mallet and chisel to enable them to split their skulls in the fight if they ran away. -- Flaubert, Salammbô, VIII
Hasdrubal is the son of Hamilcar, and the brother of Hannibal. Flaubert's novel takes place during the Mercenary War (circa 240, Hasdrubal was probably not yet born), and the Livy quotation refers to the Second Punic War, more precisely to the Battle of the Metaurus (207) -- that is, afterwards.
In other words, Flaubert is guilty of anachronism. But he was certainly aware of that, and favored the literary effect over the historical accuracy.