开发者

Can I have a persistent PDO object which just accepts new variables to be bound from AJAX calls?

开发者 https://www.devze.com 2023-03-12 04:30 出处:网络
If i would like to create an ajax search (user fills in form elements, upon any update to the form elements, the search results are updated live.)

If i would like to create an ajax search (user fills in form elements, upon any update to the form elements, the search results are updated live.)

Is it possible to create a persistent (prepared) PDO connection which only requires the new variables sent over ajax to be bound/executed?

Is there another smart way to do this?

Edit: Just to be clear, and maybe more specific: what I开发者_StackOverflow中文版 am looking for is a persistent prepared statement across connections.


You can estabilish persistent connection using:

http://php.net/manual/en/pdo.connections.php

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array(
    PDO::ATTR_PERSISTENT => true
));

That way if you have to reconnect on new request, PDO will use connection from the pool rather than create new one. If you use prepared statements with prepare() and bindParam() query will be compiled on the database side and run faster that usual query.

Some links on caching:

http://www.snipe.net/2009/03/quick-and-dirty-php-caching/

http://docstore.mik.ua/orelly/webprog/pcook/ch10_15.htm

http://mysqlhacker.com/kabir/performance/understanding-mysql-query-cache-for-php-developers-part-i.html


I suppose you're talking about prepared statments here, not "connections".

There is no way to keep the same prepared statment between calls (ajax or not)

An alternative would be to store variables in a temporary table and to send the real request at the end of the process...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号