I've been perfecting secure database connection techniques, and got to the script below.
<?php class query_sql {
protected static $conect;
private function __construct() {
$mysql_host = "";
$mysql_base = "";
$mysql_user = "";
$mysql_pass = "";
try { self::$conect = new PDO("mysql:host=" . $mysql_host . "; dbname=" . $mysql_base, $mysql_user, $mysql_pass);
self::$conect -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$conect -> exec("set names utf8");
$conect = null; }
catch(PDOException $error) {
echo $error -> getMessage(); } }
public static function conect_sql() {
if (!self::$conect) {
new query_sql; }
return self::$conect; } }
$bind_sql = query_sql::conect_sql(); ?>
My next step is to learn how to submit values from
$mysql_host = "";
$mysql_base = "";
$mysql_user = "";
$mysql_pass = "";
along with the values below
<?php $list_information = $bind_sql -> prepare("SELECT user_email, user_name FROM usuarios WHERE user_email = :user_email LIMIT 1");
$list_information -> bindValue(":user_email", "@");
$list_information -> execute();
$list_information = $list_information -> fetchAll(); ?>
just list above and compare below (login as an example)
<?php $compare_information = $bind_sql -> prepare("SELECT user_email, user_name FROM usuarios WHERE user_email = :user_email AND user_name = :user_name LIMIT 1");
$statement_array = array(":user_email" => "@", ":user_name" => "*");
foreach($statement_array as $array_key => $array_value) {
$compare_information -> bindValue($array_key, $array_value); }
$compare_information -> execute();
$compare_information = $compare_information -> fetchAll(); ?>
To receive it so
<?php foreach($list_information as $list_information) {
echo $list_information["user_email"] . " | " . $list_information["user_name"]; } ?>
and so
<?php foreach($compare_information as $compare_information) {
echo $compare_information["user_email"] . " | " . $compare_information["user_name"]; } ?>
I just need some help on what to learn so that I can send the variables into the class so they do not have to be inside, the reason is that I have a database for each information, the destination of this script uses 4 databases so I would define which database to use in each prepare (select, delete, att etc.)