homepage Welcome to WebmasterWorld Guest from 54.197.147.90
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Ajax, PHP and MySQL. Why isn't db open?
salewit




msg:4358936
 1:33 am on Sep 6, 2011 (gmt 0)

After struggling with Ajax for a few years, I hunkered down and finally got into it. Not as difficult as it first seemed.

I do have one question regarding opening and closing the MySQL database.

Main Program
openMysqlDbFunction;
do some assorted stuff
Do the Ajax thing
do some db stuff
close database


PHP called by Ajax

do some db stuff


This will give me an error because the database is not opened.

PHP called by Ajax

openMysqlDbFunction;
do some db stuff


1) Why do I have to open it again even though it's open in the main calling program?
2) Because I'm opening it again in the Ajax PHP code, does that close the DB in the main program?
3) Suppose the Ajax routine is called several times in the Main Program. Am I not doing things cleanly? Should I close the DB in the Ajax/PHP code?

Thanks for the help.

 

penders




msg:4358984
 8:17 am on Sep 6, 2011 (gmt 0)

I initially wrote a reply regarding ajax/db but then wondered if you are referring to persistent database connections? (Although this is the JavaScript forum). Normal db connections are not persistent between requests. However, if you are querying the ajax/request process then persistent connections are probably best avoided and probably not required.

rocknbil




msg:4359135
 4:35 pm on Sep 6, 2011 (gmt 0)

Why do I have to open it again even though it's open in the main calling program?


If I get you right, you mean "the page containing the ajax" when you say "main program." So this (PHP?) page opens a connection, outputs the data, closes connection. Your Ajax request, then, is like a separate "page" being called, it has to re-open a new connection to do "whatever." And when it's done, it closes again.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved