| 25 | | $query = $pdo->prepare('SELECT * FROM :table'); |
| 26 | | $query->bindValue(':table', 'users'); |
| 27 | | $query->setFetchMode(PDO::FETCH_NUM); |
| 28 | | $x = $query->fetch(PDO::FETCH_OBJ); |
| | 22 | // You can assign anything variable to a view by using standard OOP |
| | 23 | // methods. In my welcome view, the $title variable will be assigned |
| | 24 | // the value I give it here. |
| | 25 | $welcome->title = 'Welcome to Kohana!'; |
| 30 | | echo Kohana::debug($x); |
| | 27 | // An array of links to display. Assiging variables to views is completely |
| | 28 | // asyncronous. Variables can be set in any order, and can be any type |
| | 29 | // of data, including objects. |
| | 30 | $welcome->links = array |
| | 31 | ( |
| | 32 | 'Home Page' => 'http://kohanaphp.com/', |
| | 33 | 'Documentation' => 'http://doc.kohanaphp.com/', |
| | 34 | 'Forum' => 'http://forum.kohanaphp.com/', |
| | 35 | 'License' => 'Kohana License.html', |
| | 36 | 'Donate' => 'http://kohanaphp.com/donate.html', |
| | 37 | ); |
| 32 | | foreach ($query as $row) |
| 33 | | { |
| 34 | | echo $row[0], ', ', $row[1], '<br />'; |
| 35 | | } |
| 36 | | */ |
| | 39 | // Using views inside of views is completely transparent. In the welcome |
| | 40 | // view, printing the $content variable will render the welcome_content view. |
| | 41 | $welcome->content = new View('welcome_content'); |
| | 42 | |
| | 43 | // Using render(TRUE) forces the view to display now, instead of |
| | 44 | // returning an HTML string. |
| | 45 | $welcome->render(TRUE); |
| 45 | | public function pdo() |
| 46 | | { |
| 47 | | $dbh = new PDO('mysql:host=localhost;dbname=kohana', 'root', 'html123'); |
| 48 | | /* |
| 49 | | echo Kohana::debug($dbh); |
| 50 | | |
| 51 | | $query = $dbh->query('SELECT * FROM users LIMIT 3'); |
| 52 | | $query = $dbh->query('SELECT COUNT(*) FROM users ORDER BY id DESC LIMIT 3'); |
| 53 | | echo Kohana::debug($query); |
| 54 | | echo Kohana::debug($query->queryString); |
| 55 | | // $query = $query->fetchAll(PDO::FETCH_OBJ); |
| 56 | | echo Kohana::debug($query); |
| 57 | | foreach ($query as $row) |
| 58 | | { |
| 59 | | echo Kohana::debug($row); |
| 60 | | } |
| 61 | | |
| 62 | | $query = $dbh->exec('DELETE FROM users WHERE id = 2'); |
| 63 | | echo Kohana::debug($query); |
| 64 | | |
| 65 | | $query = $dbh->prepare('INSERT INTO users (email, username) VALUES (?, ?)'); |
| 66 | | $query->bindParam(1, $email); |
| 67 | | $query->bindParam(2, $username); |
| 68 | | $email = 'joske3@host.com'; |
| 69 | | $username = 'josse3'; |
| 70 | | $execute = $query->execute(array($email, $username)); |
| 71 | | echo Kohana::debug($execute); |
| 72 | | |
| 73 | | $id = $dbh->lastInsertId(); |
| 74 | | echo Kohana::debug($id); |
| 75 | | */ |
| 76 | | $query = $dbh->prepare('SELECT ? FROM users WHERE id = ?'); |
| 77 | | echo Kohana::debug($query); |
| 78 | | $query->bindValue(1, 'username'); |
| 79 | | $query->bindValue(2, 3); |
| 80 | | |
| 81 | | $query->execute(); |
| 82 | | $result = $query->fetchAll(PDO::FETCH_OBJ); |
| 83 | | echo Kohana::debug($result); |
| 84 | | foreach ($result as $row) |
| 85 | | { |
| 86 | | echo $row->username; |
| 87 | | } |
| 88 | | echo Kohana::debug($query->rowCount()); |
| 89 | | } |