EnglishAdam
EnglishAdam

Reputation: 1390

Working with jquery-mobile and database connections

What is the required methodology to keep a database connection while working with jquery-mobile?

I have from the start a ** connections.php**

This file tries to create a global and persistant connection as so...

function connect() {
    global $conn; 

$hostdb = 'localhost';
$namedb = 'xxxx';
$userdb = 'xxx';
$passdb = 'xxx';

$dsn = "mysql:host=$hostdb;dbname=$namedb;charset=utf8";
$opt = array(
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_PERSISTENT => true
);//here i have added a persistent connection!!
$conn = new PDO($dsn, $userdb, $passdb, $opt);

}

The site is within jqueryMobile which keeps the current page in the browser and loads the next relevant .php as required.

I have been unable to find specific information on how jqueryMobile works in relation to using various php pages and how persistant the connection is.

Does jqueryMobile negate the need for persistancy?

Do I need to establish the connection on each .php page as it gets called (and produces the next 'html')?

Do I need to pass the global variable $conn to the various functions (that are REQUIRED from a separate .php page) that require a database connection?

Upvotes: 0

Views: 347

Answers (1)

BillyBigPotatoes
BillyBigPotatoes

Reputation: 1338

Persistant connections can be implemented between the PHP process and MySQL - but generally as the PHP process is terminated once the request has been process there does not appear to be any benefit for you in using them.

The Javascript should not know anything about the DB implementation or if persistance is being used.

JQueryMobile does not negate the need for persistency - it does not have any interested in it.

If you are confusing DB persistance with state - then you should look to sessions and cookies to deal with the state of the web app.

Upvotes: 1

Related Questions