/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// simple DB access functions function dbGetConn() { static $conn; if (!$conn) { } return $conn; } function dbSelect($sql) { if (!$rs) { } $results[] = $row; } return $results; } // return a hash of data like array(100,200,300) // or when two columns are selected, like array('a'=>100,'b'=>200,'c'=>300) function dbSelectHash($sql) { if (!$rs) { } // get the first row so we can check if there are one or two columns selected if (!$row) { } // one column selected; just use numeric keys $results[] = $row[0]; $results[] = $row[0]; } } else { // two or more columns selected; use the first column value as the key and the second column value as the value $results[$row[0]] = $row[1]; $results[$row[0]] = $row[1]; } } return $results; }