php - Reusing Ajax Established Database Connection

41

Two Files involved:

index.php (html markup, db connection and class object)

getajax.php (db connection, sql + response code)

Need to see how can I eliminate the duplicate connection details off the getajax file and reuse the existing class connection function or contruct on index.

Already using mysql_pconnect for connection reuse on the getajax file and index.

Should I create an extended class for "getajax" so it extends primary object?

Trying to avoid overkill on DB when lots of calls are made to sql.

106

Answer

Solution:

Simply using pconnect is sufficient. As noted in the PHP documentation about persistent database connections:

they do not give you an ability to open 'user sessions' on the same link

That is, simply using pconnect tells PHP to use an existing connection if it's available. Whether or not it was the same connection used by the first PHP call is unimportant.

Make sure you read that PHP manual page - there are some important caveats.

People are also looking for solutions to the problem: PHP -- int typecast of numeric string value giving 0

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.