Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include('connect.php');
- //include this file. This is our class
- $connection = new connection_to_db;
- //instantiate class
- $connection->make_connection("host_name", "user", "pass", "database_name");
- //1st param: your host name
- //2st param: your username
- //3rd param: your password
- //4th param: your database name
- $connection->run_test_query("shouts", "id", 2);
- //1st param: your table name.
- //2nd param: which column to show.
- //3rd param: how many results to display.
- class connection_to_db{
- function make_connection($host, $user, $pass, $db){
- global $conn;
- try{
- $conn = new pdo("mysql: host=". $host . ";dbname=". $db, $user, $pass);
- }catch(PDOException $error){
- echo $error->getMessage();
- die();
- }
- }
- function run_test_query($shouts, $column_to_show, $count){
- global $conn;
- $query = $conn->prepare("SELECT * FROM $shouts LIMIT $count");
- $query->execute();
- while($result = $query->fetch(PDO::FETCH_ASSOC) ){
- echo $result["$column_to_show"] . "</br>";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement