Uhhh it depends on the game and how it works. Who are the characters, what is the plot, what do you do in the game, what's the main source of "player persistence" (how does a player "keep going" - usually a type of money or something) ...
it depends how fast you want people to be able to level, and how much experience users are able to obtain per kill or quest or whatever.
in some games, like asherons call, the experience scale was exponential (i think). I believe there were 126 levels, and after about level 100, it seemed like it would take decades to get to the next level.
in other games, like everquest 1, the first 10 or 15 levels were very quick and easy, and then it just became increasingly difficult to level, but not unbearable.
you're going to have to decide what you want the user experience to be like, and then you can choose a basic algorithm and spend a lot of time tweaking it until you're satisfied
Well, unless the experience you get from each kill gets less and less, it has to be exponential. The speed of your system not only depends on your experience formula, but also how much experience you give for each kill.
If you mean changing $k to $level, then that's just preference. That won't change the program, just the code. If you mean physically changing $k = 1 to $k = $level, the variable $level isn't initialized yet. It would most likely just be the same as $k = 0.
The script I wrote has nothing to do with a database. In my game I use that script to add each level to a database and then I check what level they are by comparing their experience with the database.