Exemple #1
0
function select_query(Db_Mysql $db)
{
    $stmt = "SELECT * FROM user";
    // query result
    $result = $db->query($stmt);
    if (!$result) {
        echo $db->errno() . ' ' . $db->error();
    } else {
        // gets the number of affected rows
        $num_rows = $db->affectedRows();
        // gets the auto generated id used in the last query
        $insert_id = $db->insertId();
        // if there are some rows
        if ($num_rows > 0) {
            $rows = array();
            // fetch a result row as an associative array
            while ($row = $db->fetch($result, MYSQLI_ASSOC)) {
                $rows[] = array('fullname' => $row['fullname'], 'email' => $row['email'], 'country' => $row['country']);
            }
            // prints results
            $content = '<div class="table-responsive"><table class="table table-condensed">
                            <thead>
                                <tr>
                                    <th>Full name</th>
                                    <th>Email</th>
                                    <th>Country</th>
                                </tr>
                            </thead>';
            foreach ($rows as $iter) {
                $content .= '<tbody>
                            <tr>
                                <td>' . $iter['fullname'] . '</td>
                                <td><a href="mailto:' . $iter['email'] . '">' . $iter['email'] . '</a></td>
                                <td>' . $iter['country'] . '</td>
                            </tr>';
            }
            $content .= '</tbody></table></div>';
            echo $content;
            echo 'Number of affected rows: ' . $num_rows . '<br>';
            echo 'Auto generated id used in the last query: ' . $insert_id;
        } else {
            echo 'There are no rows in the database.';
        }
    }
}
<div style="padding: 20% 20%;">
	<a href="index.php">Index</a>
	<a href="insert.php">Insert</a>
	<a href="select.php">Select</a>
	<a href="update.php">Update</a>
	<a href="delete.php">Delete</a>
</div>
<?php 
require_once 'db/mysql.php';
$db = new Db_Mysql(array('dbname' => 'shift_planning_test', 'username' => 'root', 'password' => '', 'host' => 'localhost'));
$fullname = "Konstantin Petrovic";
$email = "*****@*****.**";
$country = "Serbia";
$query_select = "SELECT fullname, country FROM user";
$db->connect();
$result = $db->query($query_select);
if ($result == false) {
    echo $db->error() . " " . $db->errno();
} else {
    while ($select = $db->fetch($result)) {
        foreach ($select as $something) {
            echo $something['fullname'] . " " . $something['country'] . "<br />";
        }
    }
}
$db->close();
Exemple #3
0
<?php

ini_set('display_errors', 'on');
error_reporting(E_ALL);
require_once 'db/mysql.php';
require 'select.php';
require 'delete.php';
require 'insert.php';
require 'update.php';
$db = new Db_Mysql(array('dbname' => 'shift_planning_test', 'username' => 'root', 'password' => NULL, 'host' => 'localhost'));
$db->connect();
echo '<br>';
$db->ping();
echo '<br>';
$result = $db->query(SELECT::$query);
$db->fetch($result, $resultType = null);
echo '<br>';
$db->affectedRows();
echo '<br>';
$db->insertId();
echo '<br>';
$unescapedString = "ASDASDAS";
$db->escape($unescapedString);
echo '<br>';
$db->close();
Exemple #4
0
<?php

require_once 'db/mysql.php';
$db = new Db_Mysql(array('dbname' => 'shift_planning_test', 'username' => 'root', 'password' => 'root', 'host' => 'localhost'));
$id = "18";
$name = "test";
$email = "email";
$country = "country";
$query = "SELECT * FROM user WHERE fullname LIKE '%ll%'";
$db->connect();
$db->escape($query);
$result = $db->query($query);
if ($db->affectedRows() > 0) {
    while ($row = $db->fetch($result, MYSQLI_BOTH)) {
        echo $row["fullname"] . "<br>";
    }
}
$db->close();