MySQL voorbeelden
On this page you can find some example SQL commands.
SQL update
Here is an example to update rows in column with specific data, as example the wordpress database where all pages are reverted to the defaul template:
1 2 3 |
UPDATE wp_postmeta SET meta_value = 'default' WHERE meta_key = '_wp_page_template'; |
SQL zoek en vervang data in een kolom
1 2 |
UPDATE tabel SET kolomnaam = REPLACE(kolomnaam,'http://mijnsite.nl/webshop','http://webshop.mijnsite.nl') |
SQL verwijder data in een kolom
1 |
DELETE FROM tabelnaam WHERE kolomnaam = 'string'; |
PHP SQL Fetch array
Here is a PHP example to show data from a database:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php // Database instellingen (MySQL) $db_adres = 'webadres of ip'; $db_name = 'datbasenaam'; $db_usr = 'database gebruiker'; $db_pw = 'database wachtwoord'; echo "- Bezig met verbinden..."; $dbcon = mysqli_connect($db_adres, $db_usr, $db_pw, $db_name); if (mysqli_connect_errno()) { exit; } echo "OK...<br><br>"; $query = " SELECT product_id, minimum FROM oc_product "; $result = mysqli_query($dbcon, $query); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { // waar minimum > 1 if ($row["minimum"] > 1) { echo $row["minimum"] . "," . $row["product_id"] . "<br>"; } } } else { echo "0 results"; } echo "*************************<br>"; echo "<br>"; mysqli_close($dbcon); echo "- Einde!<br>" ?> |