Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion MysqliDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,9 @@ protected function _buildInsertQuery($tableData)
$isInsert = preg_match('/^[INSERT|REPLACE]/', $this->_query);
$dataColumns = array_keys($tableData);
if ($isInsert) {
$this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) VALUES (';
if (isset ($dataColumns[0]))
$this->_query .= ' (`' . implode($dataColumns, '`, `') . '`) ';
$this->_query .= ' VALUES (';
} else {
$this->_query .= " SET ";
}
Expand Down
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements
**[Subqueries](#subqueries)**
**[EXISTS / NOT EXISTS condition](#exists--not-exists-condition)**
**[Has method](#has-method)**
**[Helper Functions](#helper-commands)**
**[Helper Methods](#helper-methods)**
**[Transaction Helpers](#transaction-helpers)**

### Installation
Expand Down Expand Up @@ -582,7 +582,7 @@ if($db->has("users")) {
return "Wrong user/password";
}
```
### Helper commands
### Helper methods
Reconnect in case mysql connection died:
```php
if (!$db->ping())
Expand All @@ -601,6 +601,12 @@ Check if table exists:
if ($db->tableExists ('users'))
echo "hooray";
```

mysqli_real_escape_string() wrapper:
```php
$escaped = $db->escape ("' and 1=1");
```

### Transaction helpers
Please keep in mind that transactions are working on innoDB tables.
Rollback transaction if insert fails:
Expand Down