/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // import PEAR DB libraries. require_once("DB.php"); // Connects to database, returns PEAR DB Object. function connect() { $db =& DB::connect("mysql://user:password@host/database"); if(DB::isError($db)) { } return $db; } // Returns a list of Arrays containing the results function execute_query($sql) { $conn = connect(); $resultset = $conn->query($sql); if(PEAR::isError($resultset)) { } while($row =& $resultset->fetchRow(DB_FETCHMODE_ASSOC)) { $results[] = $row; } $conn->disconnect(); return $results; } ?>