CSI: PHP

"Looking at your tweets I cannot even fathom what your job is. CSI:PHP?" — @grmpyprogrammer

Database Abstraction at Not Its Finest

| Comments

I see what you’re trying to do here, and I commend you for your creativity in problem solving, but I can’t help but think you’re doing it wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

// MSSQL SQL string for getting top 5 rows from a query
function top($value)
{
    if (DB_SERVER == 'MSSQL') {
        $string = " TOP " . $value . " ";
    } elseif (DB_SERVER == 'MYSQL') {
        $string = "";
    } else {
        die('Error: Database server not supported !');
    }
    return $string;
}

// MYSQL SQL string for getting top 5 rows from a query
function limit($value)
{
    if (DB_SERVER == 'MSSQL') {
        $string = "";
    } elseif (DB_SERVER == 'MYSQL') {
        $string = " LIMIT 0, " . $value . " ";
    } else {
        die('Error: Database server not supported !');
    }
    return $string;
}

Comments