Simple User Registration Using Just PHP
Create the table in the Database:
create table usuario( id integer primary key AUTO_INCREMENT, nome varchar(200) not null, sobrenome varchar(300) not null, idade integer not null, sexo char(1) not null )
Configure the Conexao.php file within the 'app/conexao' folder:
Add the code below within the getConexão() function, if your database is Mysql it is already the default.
Remember to change the data (dbname, user, password) in the connection according to your bank.
-Connection to MySql
if (!isset(self::$instance)) { self::$instance = new PDO('mysql:host=localhost;dbname=github', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$instance->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING); } return self::$instance;
-Connection to PostgreSql
$host = 'localhost;port=5432'; $dbname = 'github'; $user = 'root'; $pass = ''; try { if (!isset(self::$instance)) { self::$instance = new \PDO('pgsql:host='.$host.';dbname=' . $dbname . ';options=\'--client_encoding=UTF8\'', $user, $pass); self::$instance->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); self::$instance->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_EMPTY_STRING); } return self::$instance; } catch (Exception $ex) { echo $ex.'<br>'; }
Brayan Monteiro
include_once "./app/conexao/Conexao.php";
include_once "./app/dao/UsuarioDAO.php";
include_once "./app/model/Usuario.php";
//instantiates classes
$user = new User();
$usuariodao = new UsuarioDAO();
?>