Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class agente {
- function __construct() {
- // conectamos sql
- $servername = "localhost";
- $username = "root";
- $password = "??????";
- $dbname = "agentes";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e)
- {
- echo "Error: " . $e->getMessage();
- }
- }
- public function addUser($nick,$mail,$type = 0) {
- try {
- $stmt = $conn->prepare("INSERT INTO users (nickname, email, type)
- VALUES (:nickname, :email, :type)");
- $stmt->bindParam(':nickname', $firstname);
- $stmt->bindParam(':email', $lastname);
- $stmt->bindParam(':type', $email);
- $stmt->execute();
- } catch(PDOException $e) { echo "Error: " . $e->getMessage(); }
- }
- public function changeStatus($uid,$type) {
- try {
- $sql = "UPDATE users SET status='$type' WHERE id='$uid'";
- // Prepare statement
- $stmt = $conn->prepare($sql);
- // execute the query
- $stmt->execute();
- // echo a message to say the UPDATE succeeded
- echo $stmt->rowCount() . " records UPDATED successfully";
- } catch(PDOException $e) { echo "Error: " . $e->getMessage(); }
- }
- public function getUsers() {
- try {
- $sql = "SELECT id, nickname, status FROM users";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) {
- echo "Id: " . $row["id"]. " - Nombre: " . $row["nickname"]. " " . $row["status"]. "<br>";
- }
- } else {
- echo "0 results";
- }
- } catch(PDOException $e) { echo "Error: " . $e->getMessage(); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement