예제 #1
0
파일: update.php 프로젝트: savicmi/tasks
function update_query(Db_Mysql $db)
{
    $country = $db->escape('Serbia');
    $stmt = "UPDATE user\n             SET country = '{$country}'\n             WHERE country = 'Burundi'";
    // 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();
        echo 'Number of affected rows: ' . $num_rows . '<br>';
        echo 'Auto generated id used in the last query: ' . $insert_id;
    }
}
예제 #2
0
파일: delete.php 프로젝트: savicmi/tasks
function delete_query(Db_Mysql $db)
{
    $id = 15;
    $stmt = "DELETE FROM user\n             WHERE user_id = '{$id}'";
    // 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();
        echo 'Number of affected rows: ' . $num_rows . '<br>';
        echo 'Auto generated id used in the last query: ' . $insert_id;
    }
}
예제 #3
0
파일: select.php 프로젝트: savicmi/tasks
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.';
        }
    }
}
예제 #4
0
파일: insert.php 프로젝트: savicmi/tasks
function insert_query(Db_Mysql $db)
{
    $fullname = $db->escape('Miloš Savić');
    $email = $db->escape('*****@*****.**');
    $country = $db->escape('Serbia');
    $stmt = "INSERT INTO user (fullname, email, country)\n             VALUES ('{$fullname}', '{$email}', '{$country}')";
    // 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();
        echo 'Number of affected rows: ' . $num_rows . '<br>';
        echo 'Auto generated id used in the last query: ' . $insert_id;
    }
}
<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_update = "UPDATE user SET fullname = '{$fullname}', email = '{$email}', country = '{$country}' WHERE user_id=20";
$db->connect();
$result = $db->query($query_update);
if ($result == false) {
    echo $db->error() . " " . $db->errno();
} else {
    $update = $db->affectedRows();
    echo $update;
}
$db->close();
예제 #6
0
<?php

require_once 'db/mysql.php';
$db = new Db_Mysql(array('dbname' => 'shift_planning_test', 'username' => 'root', 'password' => 'root', 'host' => 'localhost'));
$id = "20";
$query = "DELETE FROM user WHERE user_id=" . $id;
$db->connect();
$db->escape($query);
$db->query($query);
$db->close();
header('Location: index.php');
예제 #7
0
파일: index.php 프로젝트: nikola993/task8
<?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();
<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_delete = "DELETE FROM user WHERE user_id=24";
$db->connect();
$result = $db->query($query_delete);
if ($result == false) {
    echo $db->error() . " " . $db->errno();
} else {
    $delete = $db->affectedRows();
    echo $delete;
}
$db->close();
<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();
<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_insert = "INSERT INTO user (fullname, email, country) VALUES ('{$fullname}', '{$email}', '{$country}')";
$db->connect();
$result = $db->query($query_insert);
if ($result == false) {
    echo $db->error() . " " . $db->errno();
} else {
    $insert = $db->insertId();
    echo $insert;
}
$db->close();
예제 #11
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();