I wrote a portal for my company that has dozens of ajax calls in it. For every ajax call, the target script uses mysql and session variables. on every one of those scripts I do:
page.php
$.ajax({
type:"POST",
data:someData,
url:target.php,
success:function(result){
someAction
}
});
target.php
<?php
session_start();
//target from ajax.php
require_once('/var/www/lib/db.php');
......
......
$_SESSION['someVar'] = $someMysqlResult;
db.php
$db = new PDO('mysql:host=localhost;dbname=someDB', 'someUser', 'somePassword');
so I am setting up new mysql connections dozens of times. Is there a better way? Is there a mysql resource I can carry across all of these ajax calls?
I am also starting the session dozens of times. Is there a better way to open the session again on the target script?