I am developing a Wordpress site, which will handle user registration, friends, teams and soccer tournament brackets.
On this site I have the wordpress core database and a few custom non-wordpress tables, that I have made myself.
I would like to use the Wordpress global $wpdb variable to make CRUD requests on my custom tables.
Question:
Will I run into concurrency problems with the $wpdb variable, when multiple users use it at the same time?
Example:
There are 10 users online, each of whom makes an INSERT call to the sql_tournament table. The INSERT command on $wpdb, when executed successfully, fills in the $wpdb->insert_id variable. Will each users INSERT request change the $wpdb->insert_id variable for everyone (aka. globally) or will everyone have a separate $wpdb instance, making it safe to use, because I can safely assume that when retrieveing the $wpdb->insert_id variable, I will get ID of the table that was inserted by the same Session.
Code example:
function team_add( $name, $team_website = '', $team_logo_url = '' )
{
global $wpdb;
$return = $wpdb->insert( DB_TEAM,
array(
'name' => $name,
'team_website' => $team_website,
'team_logo_url' => $team_logo_url
),
array(
'%s',
'%s',
'%s'
)
);
if ( $return === false ) {
throw new Exception( "Could not add team.." );
}
return $wpdb->insert_id;
}
Aucun commentaire:
Enregistrer un commentaire