Making $dbh global allows it to live outside of the encapsulated function
Using a prepared statement is more secure and can lead to performance increases in cases where a single query is used repetitively.
The '?' and ':artist_id' signify place holders.
When you do:
$artist_stm = $dbh->prepare($sql_artist)
Prepare sees these place holders and returns a PDO statement which incorporates these placeholders and can be executed. When you call execute on the statement you give it an array that fills in the placeholders.
Also note the order of insertion here - Artist before Album. The Artist record is inserted before the Album since Album has a foreign key that references Artist.
The 'LIKE' command tells the search to look for things matching the pattern between the % signs.