Skip to content
Browse files

Conversion of SQL constants to string blocks rather than heredocs

  • Loading branch information...
1 parent e6a60b1 commit aa055f062530d3afc5aa64cad4b69c84eecbd9f2 @b-turchyn committed May 25, 2011
Showing with 15 additions and 13 deletions.
  1. +11 −13 src/classes/sql.php
  2. +4 −0 src/index.php
View
24 src/classes/sql.php
@@ -28,32 +28,29 @@ class MySQLQueries {
const getEras = "SELECT * FROM ?eras ORDER BY name ASC";
// Count number of first names
- const getFirstNameCount = <<<'EOT'
- SELECT COUNT(*) FROM ?names
- WHERE isfirstname_sw = true
+ const getFirstNameCount =
+ "SELECT COUNT(*) FROM ?names
+ WHERE isfirstname_sw = true
AND era = ?
AND ( gender = ? OR gender = ? )
- AND deleted_dt IS NOT NULL
-EOT;
+ AND deleted_dt IS NOT NULL";
// Count number of last names
- const getLastNameCount = <<<'EOT'
- SELECT COUNT(*) FROM ?names
+ const getLastNameCount =
+ "SELECT COUNT(*) FROM ?names
WHERE isfirstname_sw = false
AND era = ?
AND ( gender = ? OR gender = ? )
- AND deleted_dt IS NOT NULL
-EOT;
+ AND deleted_dt IS NOT NULL";
// Retrieve first and last name from a random index
- const getFullName = <<<'EOT'
- SELECT name FROM ?names
+ const getFullName =
+ "SELECT name FROM ?names
WHERE isfirstname_sw = true
LIMIT ?, 1
UNION SELECT name FROM ?names
WHERE isfirstname_sw = false
- LIMIT ?, 1
-EOT;
+ LIMIT ?, 1";
function __construct($server, $user, $password, $database) {
$this->conn = new mysqli($server, $user, $password, $database);
@@ -62,6 +59,7 @@ function __construct($server, $user, $password, $database) {
if(mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
}
+ echo $this->conn;
}
function __destruct() {
View
4 src/index.php
@@ -17,4 +17,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
************************************************************************/
+
+require_once 'classes/sql.php';
+
+$sql = new MySQLQueries("localhost", "bturchyn_chargen", "dummypass", "bturchyn_chargen");
?>

0 comments on commit aa055f0

Please sign in to comment.
Something went wrong with that request. Please try again.