v5:reference:loadbalancer:getconnection
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| v5:reference:loadbalancer:getconnection [2017/05/11 00:40] – mnewnham | v5:reference:loadbalancer:getconnection [2017/05/11 00:51] (current) – [Usage] mnewnham | ||
|---|---|---|---|
| Line 24: | Line 24: | ||
| ===== Usage ===== | ===== Usage ===== | ||
| If the system could not determine whether the command to be executed is read-only or not, for example in a stored procedure, then this method can be used to retrieve a connection of the appropriate type. | If the system could not determine whether the command to be executed is read-only or not, for example in a stored procedure, then this method can be used to retrieve a connection of the appropriate type. | ||
| + | <code php> | ||
| + | $db = new ADOdbLoadBalancer; | ||
| + | |||
| + | $driver = ' | ||
| + | $database = ' | ||
| + | $user = ' | ||
| + | $password = ' | ||
| + | $host = ' | ||
| + | $db0 = new ADOdbLoadBalancerConnection( $driver, | ||
| + | ' | ||
| + | 10, | ||
| + | false, | ||
| + | $host, | ||
| + | $user, | ||
| + | $password, | ||
| + | $database ); | ||
| + | /* | ||
| + | * Add the connection to the pool | ||
| + | */ | ||
| + | $db-> | ||
| + | $db1 = new ADOdbLoadBalancerConnection( $driver, | ||
| + | ' | ||
| + | 10, | ||
| + | false, | ||
| + | $host, | ||
| + | $user, | ||
| + | $password, | ||
| + | $database ); | ||
| + | /* | ||
| + | * Add the connection to the pool | ||
| + | */ | ||
| + | $db-> | ||
| + | /* | ||
| + | * Execute something to ensure connection accuracy | ||
| + | */ | ||
| + | $db-> | ||
| + | |||
| + | /* | ||
| + | * Find a readwrite connection, pin it for the next statement | ||
| + | */ | ||
| + | $db-> | ||
| + | |||
| + | /* | ||
| + | * Now construct a stored procedure and execute it against $db, | ||
| + | * because it is pinned, it will execute against the ' | ||
| + | */ | ||
| + | $stmt = $db-> | ||
| + | $val1 = ' | ||
| + | $par1 = ' | ||
| + | $db-> | ||
| + | $db-> | ||
| + | </ | ||
v5/reference/loadbalancer/getconnection.1494456052.txt.gz · Last modified: by mnewnham
