summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIndieteq <admin@indieteq.com>2014-01-06 18:42:27 +0100
committerIndieteq <admin@indieteq.com>2014-01-06 18:42:27 +0100
commit086c72ca2a679da6b63b9945332a2514c961e162 (patch)
tree76db7531f41bf5edfbcc5e90dfd72608bc77496d
parentc995f7ce676780156de564fbc5471c8aa8069ff5 (diff)
downloadphp-mysql-pdo-database-class-086c72ca2a679da6b63b9945332a2514c961e162.zip
php-mysql-pdo-database-class-086c72ca2a679da6b63b9945332a2514c961e162.tar.gz
php-mysql-pdo-database-class-086c72ca2a679da6b63b9945332a2514c961e162.tar.bz2
UTF8, Query method fix
When pdo object is initialized the encoding is set to utf8. when writing sql statements with lower case the query method will call the correct method instead of returning null.
-rw-r--r--Db.class.php13
1 files changed, 8 insertions, 5 deletions
diff --git a/Db.class.php b/Db.class.php
index 53f0d72..bdf2954 100644
--- a/Db.class.php
+++ b/Db.class.php
@@ -56,8 +56,8 @@ class DB
$dsn = 'mysql:dbname='.$this->settings["dbname"].';host='.$this->settings["host"].'';
try
{
- # Read settings from INI file
- $this->pdo = new PDO($dsn, $this->settings["user"], $this->settings["password"]);
+ # Read settings from INI file, set UTF8
+ $this->pdo = new PDO($dsn, $this->settings["user"], $this->settings["password"], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
# We can now log any exceptions on Fatal error.
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@@ -165,16 +165,19 @@ class DB
* @param int $fetchmode
* @return mixed
*/
- public function query($query,$params = null,$fetchmode = PDO::FETCH_ASSOC)
+ public function query($query,$params = null, $fetchmode = PDO::FETCH_ASSOC)
{
$query = trim($query);
$this->Init($query,$params);
- if (stripos($query, 'select') === 0){
+ # Assuming there are spaces in the query. Otherwise it would be an invalid query.
+ $statement = strtolower(substr($query, 0 , 6));
+
+ if ($statement === 'select') {
return $this->sQuery->fetchAll($fetchmode);
}
- elseif (stripos($query, 'insert') === 0 || stripos($query, 'update') === 0 || stripos($query, 'delete') === 0) {
+ elseif ( $statement === 'insert' || $statement === 'update' || $statement === 'delete' ) {
return $this->sQuery->rowCount();
}
else {