Skip to content

Commit 38e3c23

Browse files
committed
update, added queryResutl() needed a clear way to get results if query_prepared is used directly
1 parent eb1108c commit 38e3c23

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ prepareOff(); // When off shortcut SQL Methods calls will use vendors escape rou
121121
// With the same number of arguments in an array.
122122
// It will determine arguments type, execute, and return results.
123123
query_prepared(string $query_string, array $param_array);
124+
// Will need to call to get last successful query result, will return an object array
125+
queryResult();
124126
```
125127

126128
#### Example for using prepare statements indirectly, with above shortcut SQL methods
@@ -178,7 +180,14 @@ foreach ($result as $row) {
178180
#### Example for using prepare statements directly, no shortcut SQL methods used
179181

180182
```php
181-
$db->query_prepared('INSERT INTO profile( name, email, phone) VALUES( ?, ?, ? )', [$user, $address, $number]);
183+
$db->query_prepared('INSERT INTO profile( name, email, phone) VALUES( ?, ?, ? );', [$user, $address, $number]);
184+
185+
$db->query_prepared('SELECT name, email FROM profile WHERE phone = ? OR id != ?', [$number, 5]);
186+
$result = $db->queryResult(); // the last query that has results are stored in `last_result` protected property
187+
188+
foreach ($result as $row) {
189+
echo $row->name.' '.$row->email);
190+
}
182191
```
183192

184193
## For Authors and **[Contributors](https://github.com/ezSQL/ezsql/blob/master/CONTRIBUTORS.md)**

lib/ezsqlModel.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,12 @@ public function timer_update_global($timer_name)
626626
}
627627

628628
/**
629-
* Function for operating query count
630-
*
631-
* @param bool $all Set to false for function to return queries only during this connection
632-
* @param bool $increase Set to true to increase query count (internal usage)
633-
* @return int Returns query count base on $all
634-
*/
629+
* Function for operating query count
630+
*
631+
* @param bool $all Set to false for function to return queries only during this connection
632+
* @param bool $increase Set to true to increase query count (internal usage)
633+
* @return int Returns query count base on $all
634+
*/
635635
public function count($all = true, $increase = false)
636636
{
637637
if ($increase) {
@@ -642,23 +642,33 @@ public function count($all = true, $increase = false)
642642
return ($all) ? $this->num_queries : $this->conn_queries;
643643
}
644644

645-
/**
646-
* Returns, whether a database connection is established, or not
647-
*
648-
* @return boolean
649-
*/
645+
/**
646+
* Returns, whether a database connection is established, or not
647+
*
648+
* @return boolean
649+
*/
650650
public function isConnected()
651651
{
652652
return $this->_connected;
653-
} // isConnected
653+
} // isConnected
654654

655-
/**
656-
* Returns the affected rows of a query
657-
*
658-
* @return int
659-
*/
655+
/**
656+
* Returns the affected rows of a query
657+
*
658+
* @return int
659+
*/
660660
public function affectedRows()
661661
{
662662
return $this->_affectedRows;
663-
} // affectedRows
663+
} // affectedRows
664+
665+
/**
666+
* Returns the last query result
667+
*
668+
* @return array
669+
*/
670+
public function queryResult()
671+
{
672+
return $this->last_result;
673+
}
664674
} // ezsqlModel

0 commit comments

Comments
 (0)