Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once "Connection.php";
- $dbconnection = new Database('localhost', 'root', '', 'cardimages');
- $Name = $_POST['cardname'];
- $Colour = $_POST['colour'];
- $Rarity = $_POST['rarity'];
- $CardQuery = "INSERT INTO `testimage` (`Name`, `Colour`, `Rarity`) VALUES (:Name, :Colour, :Rarity)";
- $CardResult = $dbconnection->Connection->prepare($CardQuery);
- $CardExec = $CardResult->execute(array(":Name"=>$Name,":Colour"=>$Colour,":Rarity"=>$Rarity));
- if ($CardExec) {
- Echo "The data was inserted!";
- } else {
- echo "The data wasn't inserted!";
- }
- $query_array = array('name'=>$_POST['cardname'], 'type'=> 'card', '.jpg');
- $url = "http://gatherer.wizards.com/Handlers/Image.ashx?".http_build_query($query_array);
- $img = "Images/" . ucwords($Name) . ".png";
- file_put_contents($img, file_get_contents($url));
- ?>
- <?php
- Class Database {
- private $hostname;
- private $username;
- private $password;
- private $database;
- public $Connection;
- public function __construct($hostname, $username, $password, $database) {
- $this->hostname;
- $this->username;
- $this->password;
- $this->database;
- $this->Connect();
- }
- private function SetHostname($hostname) {
- $this->hostname = $hostname;
- return $this;
- }
- private function SetUsername($username) {
- $this->username = $username;
- return $this;
- }
- private function SetPassword($password) {
- $this->password = $password;
- return $this;
- }
- private function SetDatabase($database) {
- $this->database = $database;
- return $this;
- }
- public function GetHostname() {
- return $this->hostname;
- }
- public function GetUsername() {
- return $this->username;
- }
- public function GetPassword() {
- return $this->password;
- }
- public function GetDatabase() {
- return $this->database;
- }
- private function Connect() {
- try
- {
- $db = $this->Connection = new PDO('mysql:host=' . $this->hostname . ';dbname=' . $this->database . '', $this->username, $this->password);
- echo "This connected successfully!";
- }
- catch (PDOException $e)
- {
- echo "It didn't connect to the database!";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement