-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimization, and start of Database Plugin
- Loading branch information
RyanNaddy
authored and
RyanNaddy
committed
Jul 15, 2013
1 parent
24434c4
commit 2537f12
Showing
6 changed files
with
170 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
require_once '../../phpLive.php'; | ||
|
||
$live->db->select("select * from users where fname in(?,?)", array("Ryan", "Jaimee"))->each(function($col, $name){ | ||
echo "here"; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
/* | ||
define("PDO_DATABASE", "mysql"); | ||
define("PDO_DBNAME", "test"); | ||
define("PDO_HOST", "localhost"); | ||
define("PDO_USER", "root"); | ||
define("PDO_PASSWD", "afrid123"); | ||
*/ | ||
|
||
/** | ||
* @property PDO $db PDO Class | ||
* @property PDOStatement $sql PDO Statement | ||
*/ | ||
class Database extends phpLive{ | ||
|
||
private $db = null, | ||
$dbtype = null, | ||
$database = null, | ||
$hostname = null, | ||
$username = null, | ||
$password = null | ||
|
||
; | ||
|
||
public function __construct($data){ | ||
$this->dbtype = $data["dbtype"]; | ||
$this->database = $data["database"]; | ||
$this->hostname = $data["hostname"]; | ||
$this->username = $data["username"]; | ||
$this->password = $data["password"]; | ||
parent::__construct(); | ||
} | ||
|
||
public function connect(){ | ||
$this->db = new PDO("$this->dbtype:dbname=$this->database;host=$this->hostname;", $this->username, $this->password); | ||
} | ||
|
||
private function isConnected(){ | ||
if($this->db === null){ | ||
$this->connect(); | ||
} | ||
} | ||
|
||
private function query($query, $args){ | ||
$this->isConnected(); | ||
$this->sql = $this->db->prepare($query, $args); | ||
$this->sql->execute($args); | ||
} | ||
|
||
private function queryinfo($args){ | ||
$query = array_shift($args); | ||
if(isset($args[0]) && is_array($args[0])){ | ||
$args = $args[0]; | ||
} | ||
return (object)array("query" => $query, "args" => $args); | ||
} | ||
|
||
public function select(){ | ||
$info = $this->queryinfo(func_get_args()); | ||
$this->query($info->query, $info->args); | ||
return $this; | ||
return $this->sql->fetchAll(); | ||
} | ||
|
||
public function insert(){ | ||
$info = $this->queryinfo(func_get_args()); | ||
$this->query($info->query, $info->args); | ||
return $this->db->lastInsertId(); | ||
} | ||
|
||
public function update(){ | ||
$info = $this->queryinfo(func_get_args()); | ||
$this->query($info->query, $info->args); | ||
return $this->sql->rowCount(); | ||
} | ||
|
||
public function delete(){ | ||
$info = $this->queryinfo(func_get_args()); | ||
$this->query($info->query, $info->args); | ||
return $this->sql->rowCount(); | ||
} | ||
|
||
public function getFirst(){ | ||
$info = $this->queryinfo(func_get_args()); | ||
$this->query($info->query, $info->args); | ||
return $this->sql->fetchColumn(); | ||
} | ||
|
||
public function getEntry(){ | ||
$info = $this->queryinfo(func_get_args()); | ||
$this->query($info->query, $info->args); | ||
return $this->sql->fetch(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
$plugins = array( | ||
"Twitter" => array( | ||
"root" => "TwitterAPI", | ||
"fileName" => "Twitter.plugin.php", | ||
"instanceName" => "twitter", | ||
"sessionRef" => "twitter", | ||
), | ||
"Database" => array( | ||
"root" => "Database", | ||
"fileName" => "Database.plugin.php", | ||
"instanceName" => "db", | ||
"sessionRef" => "db", | ||
"information" => array( | ||
"dbtype" => "mysql", | ||
"hostname" => "localhost", | ||
"database" => "test", | ||
"username" => "root", | ||
"password" => "afrid123", | ||
) | ||
), | ||
); |