in reply to Re^4: Help with MySQL SELECT into multidimensional array
in thread Help with MySQL SELECT into multidimensional array
A complicated statement will take a while to prepare as the data base will figure out its strategy for executing it. You can keep "reusing" a prepared query with different values. This way of doing it is also better than interpolating a different Perl variable into the statement for security reasons.
Update: you may find this feature useful in dealing with other of your queries. A common technique to run essentially the same query multiple times with different values is to create a data structure, an array, a hash table, etc and then make a loop to cycle through that structure, executing the query again and again. with different values. This can reduce the clutter of repeating the same SQL again and again.To make a parameter a variable, use a placeholder: my $query = $dbh->prepare("SELECT c2.id, c2.name as 'client' FROM client c2 WHERE level = ? and status = ?"); my $level = 50; $query->execute($level,1); $level = 60; $query->execute($level,1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Help with MySQL SELECT into multidimensional array
by btongeorge (Initiate) on Dec 02, 2011 at 15:57 UTC | |
by Marshall (Canon) on Dec 02, 2011 at 16:18 UTC | |
by btongeorge (Initiate) on Dec 02, 2011 at 16:54 UTC | |
by Marshall (Canon) on Dec 02, 2011 at 17:05 UTC | |
by btongeorge (Initiate) on Dec 02, 2011 at 17:20 UTC | |
|