View difference between Paste ID: 7jj7MLjd and 3PMARU52
SHOW: | | - or go back to the newest paste.
1
 function query(/* $sql [, ... ] */)
2
    {
3
        // SQL statement
4
        $sql = func_get_arg(0);
5
        
6
	// parameters, if any
7
        $parameters = array_slice(func_get_args(), 1);
8
        
9-
		
9+
	// try to connect to database
10
        static $handle;
11-
        // parameters, if any
11+
12
        {
13
            try
14
            {
15
                // connect to database
16
                $handle =  new PDO("mysql:dbname=" . DATABASE . ";host=" . SERVER . ";charset=utf8", USERNAME, PASSWORD);	
17-
        // try to connect to database
17+
18
                $handle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 
19
            }
20
            catch (Exception $e)
21
            {
22
                // trigger (big, orange) error
23
                trigger_error($e->getMessage(), E_USER_ERROR);
24
                exit;
25
            }
26
        }
27
28
        // prepare SQL statement
29
        $statement = $handle->prepare($sql);
30
        if ($statement === false)
31-
                $handle =  new PDO("mysql:dbname=" . DATABASE . ";host=" . SERVER . ";charset=utf8", USERNAME, PASSWORD);
31+
32
            // trigger (big, orange) error
33-
				
33+
34
            exit;
35
        }
36
        // execute SQL statement
37
        $results = $statement->execute($parameters);
38
        // return result set's rows, if any
39
        if ($results !== false)
40
        {
41
            return $statement->fetchAll(PDO::FETCH_ASSOC);
42
        }
43
        else
44
        {
45
            return false;
46
        }
47
    }