-
January 16th, 2017, 07:56 AM
#1
Converting MYSQL to PDO
Hi guys, Im new to PDO and I cant get hang of it, could anyone please help me convert mysql code to pdo
[PHP]<?php
require ("Constructor.php");
require ('Databaseinfo.php');
class GetShoplist {
function GetItemTypes() {
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "itemDB";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT DISTINCT type FROM item";
$result = $conn->query($sql);
$types = array();
while ($row = mysqli_fetch_array($result)) {
array_push($types, $row[0]);
}
return $types;
}
function GetItemByType($type) {
require 'Databaseinfo.php';
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "itemDB";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT * FROM item WHERE type LIKE '$type'";{
} $sql = "SELECT name, type, price,country,image,review FROM item";
$result = $conn->query($query);
$itemArray = array();
while ($row = mysqli_fetch_array($result)) {
$name = $row[1];
$type = $row[2];
$price = $row[3];
$country = $row[4];
$image = $row[5];
$review = $row[6];
$item = new Constructor(-1, $name, $type, $price,$country, $image, $review);
array_push($itemArray, $item);
}
return $itemArray;
}
}
?>[/PHP
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|