The PHP function PDO::lastInsertId() along with the constant ATTR_PERSISTENT provide a

I am facing a similar question to the one discussed here.

From what I gathered from that discussion, it seems that PDO::lastInsertId() is secure when called from different connections. However, does this imply that using PDO::ATTR_PERSISTENT => true in the PDO constructor should be avoided if you intend to utilize PDO::lastInsertId() within that same connection?

In simpler terms, would my application need to undergo "the overhead of establishing a new connection every time a script needs to talk to a database" as described in PDO Connections and Connection Management if I have to use PDO::lastInsertId()?

Answer №1

It does not signify anything whatsoever.

The identity of the individual who accesses the same connection subsequent to your php script concluding its operation is inconsequential. What holds significance is that you will possess the most recent inserted id generated by this connection, and not another one.

Hence, do not hesitate to employ it with both persisting and non-persisting connections.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Need to retrieve precise information from a website?

Struggling to extract information from this specific section of a webpage <div id="menu_pannel"> <ul class="sf-menu" id="nav"> <li class="current"><a href="/" class="current" >Home</a></li> <li class=""> ...

The authentication system in my Laravel 8 application runs smoothly on XAMPP Local Server, but encounters issues when deployed on cPanel. Instead of successfully authenticating users, it displays a "Page Expired"

After successfully developing an application with Laravel and implementing Laravel Auth for authentication, everything worked perfectly on my local server. However, when I decided to host the application online, I encountered a major issue. Despite input ...

Creating a personalized AJAX tab loader for Jquery UI tabs

Here is the code I am using to create Jquery UI tabs: <div id="tabs-loading-message" style="display:none">Loading, Please wait..</div> <div id="fragment-2"> <ul> <li><a href="/public/animalstab" title="Animals"& ...

What techniques can be used to streamline this regex and eliminate the need for recursion?

Regex: (?|`(?>[^`\\]|\\.|``)*`|'(?>[^'\\]|\\.|'')*'|"(?>[^"\\]|\\.|"")*"|(\?{1,2})|(:{1,2})([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)) ...

Transferring access code via mobile device

I am struggling with the code below that is supposed to send a password to a mobile device, but it doesn't seem to be working. Any help would be greatly appreciated. if (isset($_REQUEST['submit'])) { $phone = "select mobno from registr ...

What is the way to modify the contents of a div using ajax?

I have blade files in both list and image formats. There are two span buttons here, and I would like to display a list in different formats when each button is clicked. How should I go about writing the code for this? <span id="penpal-image-view" ...

What is the process for creating a widget that can be seamlessly integrated into someone’s website and hosted on your own site

In relation to this previous question. After researching JSONP and conducting some tests, I've realized that I am completely clueless about what I'm doing... What is required? I am developing a customer service tool for people to integrate in ...

Transmitting unique characters, such as a caron symbol, via xmlhttp.responseText and encoding them with json_encode

I am struggling to retrieve data from a database that contains a special character (caron) and then pass it through xmlhttp.responseText using json_encode to fill textboxes. However, the textbox linked to the data with the special character (caron) is not ...

Utilizing Stripe for Payment Processing

I'm encountering a problem with getting Stripe charging to function properly. Despite having manually loaded Composer since it wouldn't install, I am not receiving any PHP errors and the token creation is running smoothly. There don't seem t ...

PHP script unintentionally wipes out entire WordPress website

Currently, I am dynamically loading data into a WordPress site: This data is being fetched from another website: To accomplish this task, I have inserted the following code snippet into the WordPress page: <div id="this_day_in_history"> < ...

Eliminate the presence of double quotation marks in an array

I've encountered an issue while using the WhereIn() method in Laravel to retrieve various 'id' values. The data I'm receiving is in the format ["6,19"], but I actually need it to be an array of numbers without the double quotes. The da ...

Ways to effectively utilize the results from php functions triggered by ajax in our document

I have a mobile application that constantly updates latitude and longitude values to my PostgreSQL database. I am attempting to display these updated points on an OpenLayers map using jQuery and AJAX. However, I am encountering a problem: after clicking th ...

Issues arising from the utilization of SimpleXMLElement with XML data extracted from mobile.de

My goal is to retrieve XML data from mobile.de for my plugin's data preparation. The XML returned appears as follows: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <reference:reference xmlns:seller="http://services.mobile.de/sc ...

What is the process for invoking a different DetailView::widget from a separate model within a single view in YII2?

I recently started using the Yii2 framework. I have successfully displayed data for a table using DetailView::widget. Now, I am trying to call another DetailView::widget for a different table and display it on the same view. Can someone help me with this? ...

Refreshing an HTML table with new data using jQuery and Ajax after a different selection

Currently, I have a piece of code that allows me to select two players and display some statistics about them. The data is presented using a regular table (image1). The issue I am facing is that when I select a new player, instead of updating the informat ...

Is there a way for me to obtain the client ID and redirect URL after a user logs in to Instagram via my website?

My goal is for users to be able to easily import their images into my website. After reviewing their documentation, I found that they authenticate a user by providing a response code through the following URL: However, this URL only provides me with a co ...

The combination of Ajax, JavaScript, PHP/HTML, and dynamic variables

Hey there, I'm currently working on a game development project and have encountered what seems to be a scope issue. The issue arises in my js file when a player clicks on the card they want to play: It starts in my js file:</p> <pre>&l ...

The ajax call functions successfully on both local endpoints and Linux servers, however, it fails to execute on Azure servers despite returning a 200 status code

I am facing an issue with an ajax call that is working fine locally and on Linux servers, but not on Azure. The HTTP status is 200 in all environments, including Azure. The PHP directory is located in a virtual directory on Azure. Any assistance with this ...

Unable to save Ajax data in session array

Currently, I am developing a cart system using jquery, ajax, and php. The issue I am facing is that the text within the HTML elements is not being added to the session array. Below is the ajax code I am using: $(document).ready(function(){ $("#car ...

Adjust input quantities for product variations in Woocommerce

In my WooCommerce store, I encountered an issue with a variable product that has 3 product variations. Unfortunately, the quantity to sell for each variation needs to be fixed and cannot be adjusted by the customer. For instance: We have 2 Red items ava ...