Skip to content

Instantly share code, notes, and snippets.

@Oappot
Last active November 22, 2017 00:30
Show Gist options
  • Save Oappot/a122ff879dd73c9ea2b5d824a047c850 to your computer and use it in GitHub Desktop.
Save Oappot/a122ff879dd73c9ea2b5d824a047c850 to your computer and use it in GitHub Desktop.
<?php
include ('Connect.php');
$test = new Connect;
$test->createUser();
?>
<?php
class Connect {
public $connection;
public function __construct(){
$this->connect();
}
public function connect(){
$connection = new PDO('mysql:host=orfarile;dbname=orfarile', 'root', '');
}
function selectTests(){
}
public function createUser(){
$connection->query("INSERT INTO users(user_login, user_password) VALUES ('test1', 'test1')");
}
}
?>
<?php
class Connect {
private $connection;
function __construct(){
$this->connect();
}
function connect(){
$connection = new PDO('mysql:host=orfarile;dbname=orfarile', 'root', '');
$connection->query("INSERT INTO users(user_login, user_password) VALUES ('test2', 'test2')");
}
function selectTests(){
}
function createUser(){
}
}
?>
@Oappot
Copy link
Author

Oappot commented Nov 22, 2017

fixed issue#1.
issue#2:
Fatal error: Uncaught Error: Call to a member function query() on null in ~\Connect.php:19 Stack trace: #0 ~\check.php(5): Connect->createUser() #1 {main} thrown in ~\Connect.php on line 19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment