Skip to content

Commit

Permalink
1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc committed Jun 22, 2019
1 parent c3f87d9 commit 916cf58
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ $dao->getSequencePHP(true) // string(19) "1739032938181434311"

## Changelist

* 1.6 2019-jun-22 affected_rows() returns a correct value.
* 1.5 2019-may-31 some cleanups. columnTable() returns if the column is nullable or not.
* 1.4 2019-may-30 insertobject()
* 1.3 2019-may-23 New changes
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eftec/pdoone",
"description": "Procedural PDO Data access class in a single Class",
"version": "1.5",
"version": "1.6",
"type": "library",
"keywords": [
"dao",
Expand Down
4 changes: 3 additions & 1 deletion examples/testinsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
include "dBug.php";

// connecting to database sakila at 127.0.0.1 with user root and password abc.123
$dao=new PdoOne("127.0.0.1","root","abc.123","sakila","logpdoone.txt");
$dao=new PdoOne("mysql","127.0.0.1","root","abc.123","sakila","logpdoone.txt");
try {
echo "<h1>Connection. The instance {$dao->server}, base:{$dao->db} user:{$dao->user} and password:{$dao->pwd} must exists</h1>";
$dao->connect();
Expand Down Expand Up @@ -36,6 +36,8 @@
$dao->runRawQuery('insert into `typetable`(`type`,`name`) values(?,?)'
,array('i',2,'s','Yummy'));
echo $dao->lastQuery."<br>";
echo $dao->affected_rows()."<br>";
die(1);

// $dao->insert("producttype",['idproducttype','i','name','s','type','i'],[1,'Coca-Cola',1]);
$dao->from("producttype")
Expand Down
28 changes: 18 additions & 10 deletions lib/PdoOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Class PdoOne
* This class wrappes PDO but it could be used for another framework/library.
* @version 1.5 20190531
* @version 1.6 20190622
* @package eftec
* @author Jorge Castro Castillo
* @copyright (c) Jorge Castro C. MIT License https://github.com/EFTEC/PdoOne
Expand Down Expand Up @@ -79,8 +79,8 @@ class PdoOne
/** @var string last query executed */
var $lastQuery;
var $lastParam=[];


/** @var int */
private $affected_rows=0;


/**
Expand Down Expand Up @@ -285,6 +285,7 @@ public function runMultipleRawQuery($listSql, $continueOnError = false)
if (!$this->isOpen) { $this->throwError("RMRQ: It's not connected to the database",""); return false; }
$arr = explode(';', $listSql);
$ok = true;
$counter=0;
foreach ($arr as $rawSql) {
if(trim($rawSql)!='') {
if ($this->readonly) {
Expand All @@ -305,9 +306,12 @@ public function runMultipleRawQuery($listSql, $continueOnError = false)
if (!$continueOnError) {
$this->throwError("Unable to run raw query",$this->lastQuery);
}
}
} else {
$counter+=$r->rowCount();
}
}
}
$this->affected_rows=$counter;
return $ok;
}

Expand Down Expand Up @@ -1504,13 +1508,18 @@ public function runRawQuery($rawSql, $param = null, $returnArray = true)
if ($rows === false) {
$this->throwError("Unable to run raw query",$rawSql,$this->lastParam);
}

if ($returnArray && $rows instanceof PDOStatement) {
if ($rows->columnCount()>0) {
return @$rows->fetchAll(PDO::FETCH_ASSOC);
$result=@$rows->fetchAll(PDO::FETCH_ASSOC);
$this->affected_rows= $rows->rowCount();
return $result;
} else {
$this->affected_rows= $rows->rowCount();
return true;
}
} else {
$this->affected_rows= $rows->rowCount();
return $rows;
}
}
Expand All @@ -1531,9 +1540,11 @@ public function runRawQuery($rawSql, $param = null, $returnArray = true)
}
if ($returnArray && $stmt instanceof PDOStatement) {
$rows = ($stmt->columnCount()>0) ? $stmt->fetchAll(PDO::FETCH_ASSOC) : array();
$this->affected_rows= $stmt->rowCount();
$stmt=null;
return $rows;
} else {
$this->affected_rows= $stmt->rowCount();
return $stmt;
}
}
Expand Down Expand Up @@ -1567,15 +1578,12 @@ public function insert_id()
* @param PDOStatement|null|bool $stmt
* @return mixed
*/
public function affected_rows($stmt)
public function affected_rows($stmt=null)
{
if ($stmt instanceof PDOStatement) {
if (!$this->isOpen) return $stmt->rowCount();
}
if (is_array($stmt)) {
return count($stmt);
}
return 0;
return $this->affected_rows; // returns previous calculated information
}

/**
Expand Down

0 comments on commit 916cf58

Please sign in to comment.