chrisrog
Member
- Messages
- 33
- Reaction score
- 0
- Points
- 6
- What functions and setup to you recommend for an admin login feature and user login feature?
- Trying to figure out how to connect my java applets and other web applications to my DB but unsure how to do this on x10hosting.
- We all know my CSS and Design Skills are horrid so any suggestions on a good setup to the page an its CSS to make it look nice?
- Working on a php Gallery that is connected to a DB. So far it is working fine locally but not sure how to change it up to work on my live site here. (Will upload code when able to show it)
- What would you all recommend putting into php classes? Right now I got a general idea for things like my gallery and DB connection but any ideas on what else.
- Going to be working with the MySQL DB a lot here and forgot some of what we need to be using in the PDO statement that connects to it. Host being the main one? (I have a connection class working just fine at home but not sure if it'll work here when targets are changed)
Here's the DBConnection.php file.
PHP:
<?php
//$connection = createconnection('localhost','namecatch','root','');
//$connection = createconnection('localhost','cluboops','root','');
//some connections I'm using for other things at home.
function createconnection($host, $dbname, $user, $pass) {
try {
$connectiontodb = new DBConnection("mysql:host=$host;dbname=$dbname", "$user", "$pass");
return $connectiontodb;
} catch (Exception $ex) {
$error_msg = "Unknown Error in dbConnection.php! Report this! \n\n" . $except->getMessage();
include 'errorDisplayer.php';
exit();
}
}
/**
* Description of DBConnection
*
* @[USER=182410]Author[/USER] crogers
*/
class DBConnection {
private $dsn;
private $username;
private $password;
private $db;
function __construct($dsninput, $usernameinput, $passwordinput) {
$this->dsn = $dsninput;
$this->username = $usernameinput;
$this->password = $passwordinput;
try {
$this->db = new PDO($this->dsn, $this->username, $this->password);
} catch (PDOException $excep) {
echo "Something broke and I got to fix it :( : " . $excep->getMessage();
exit();
}
}
function __destruct() {
$this->dsn = null;
$this->username = null;
$this->password = null;
$this->db = null;
}
public function getDB() {
return $this->db;
}
function selectFromAny($fromtargets, $selecttargets) {
$querystatement = "SELECT $selecttargets FROM $fromtargets";
$tableinfo = $this->db->prepare($querystatement); /* $connection->getDB() */
$tableinfo->setFetchMode(PDO::FETCH_ASSOC);
$tableinfo->execute();
return $tableinfo;
}
function selectAny($fromtargets, $selecttargets, $orderbytargets) {
$querystatement = "SELECT $selecttargets FROM $fromtargets ORDER BY $orderbytargets";
$tableinfo = $this->db->prepare($querystatement);
$tableinfo->setFetchMode(PDO::FETCH_ASSOC);
$tableinfo->execute();
return $tableinfo;
}
function selectAnyWhere($fromtargets, $selecttargets, $wherecoltargets) {
$querystatement = "SELECT $selecttargets FROM $fromtargets WHERE $wherecoltargets";
$tableinfo = $this->db->prepare($querystatement);
$tableinfo->setFetchMode(PDO::FETCH_ASSOC);
$tableinfo->execute();
return $tableinfo;
}
function selectAnyWhereOrder($fromtargets, $selecttargets, $wherecoltargets, $orderbytargets) {
$querystatement = "SELECT $selecttargets FROM $fromtargets WHERE $wherecoltargets ORDER BY $orderbytargets";
$tableinfo = $this->db->prepare($querystatement);
$tableinfo->setFetchMode(PDO::FETCH_ASSOC);
$tableinfo->execute();
return $tableinfo;
}
function updateOn($updatedtablename, $arrayofcolnames, $arrayofcoldata, $wheretargets) {
$querystatement = "UPDATE $updatedtablename SET";
$colcount1 = count($arrayofcolnames);
$setlist = "";
for ($row = 0; $row < $colcount1; $row++) {
if (!is_numeric($arrayofcoldata[$row])) {
if ($row < $colcount1 - 1) {
$setlist .= " $arrayofcolnames[$row] = '$arrayofcoldata[$row]', ";
} else {
$setlist .= " $arrayofcolnames[$row] = '$arrayofcoldata[$row]' ";
}
} else {
if ($row < $colcount1 - 1) {
$setlist .= " $arrayofcolnames[$row] = $arrayofcoldata[$row], ";
} else {
$setlist .= " $arrayofcolnames[$row] = $arrayofcoldata[$row] ";
}
}
}
$querystatement .= $setlist . "WHERE $wheretargets";
$tableinfo = $this->db->prepare($querystatement);
#$tableinfo->setFetchMode(PDO::FETCH_ASSOC);
$tableinfo->execute();
return $tableinfo;
}
function deleteOn($targettable, $wheretargets) {
$querystatement = "DELETE FROM $targettable WHERE $wheretargets";
echo $querystatement;
$tableinfo = $this->db->prepare($querystatement);
#$tableinfo->setFetchMode(PDO::FETCH_ASSOC);
$tableinfo->execute();
return $tableinfo;
}
function insertItems($tablename, $stringofcolnames, $arrayofdatainput) {
$colcount1 = count($arrayofdatainput);
$setlist = "";
for ($row = 0; $row < $colcount1; $row++) {
if (!is_numeric($arrayofdatainput[$row])) {
if ($row < $colcount1 - 1) {
$setlist .= "'$arrayofdatainput[$row]', ";
} else {
$setlist .= "'$arrayofdatainput[$row]' ";
}
} else {
if ($row < $colcount1 - 1) {
$setlist .= "$arrayofdatainput[$row], ";
} else {
$setlist .= "$arrayofdatainput[$row] ";
}
}
}
echo "<br />";
$querystatement = "INSERT INTO $tablename($stringofcolnames) VALUES($setlist)";
echo $querystatement;
$tableinfo = $this->db->prepare($querystatement);
#$tableinfo->setFetchMode(PDO::FETCH_ASSOC);
$tableinfo->execute();
return $tableinfo;
}
}
Last edited: