Created
February 2, 2015 18:51
-
-
Save wgriffioen/ea799c74b21214d0635c to your computer and use it in GitHub Desktop.
PHP - MySQL voorbeeld voor Vincent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Dit is de nieuwe manier. Zo kun je het beste gaan doen. PDO lijkt een beetje op db class uit ons CMS, maar dan | |
* nog net wat beter. | |
*/ | |
$pdo = new \PDO('mysql:host=localhost;dbname=database', $username, $password); | |
// Zo haal je dan dingen op uit de database | |
$results = $pdo->query("SELECT * FROM users")->execute(); | |
// Zo maak je een query met parameters | |
$results = $pdo->query("SELECT * FROM users WHERE username = :username")->execute(array('username' => 'Wim')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Dit is de oude manier. Dit werkt nog wel tot en met PHP 5.4, maar daarna niet meer. Eigenlijk kun je het beter niet meer | |
* op deze manier doen. | |
*/ | |
$connection = null; | |
function connect() | |
{ | |
global $connection; | |
$connection = mysql_connect('host', 'username', 'password'); | |
mysql_select_db('database', $connection); | |
} | |
function query($query) | |
{ | |
global $connection; | |
return mysql_query($query, $connection); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment