}
$r = self::p("EXPLAIN ".$query);
- if (!self::is_result($r)) {
+ if (!self::isResult($r)) {
return;
}
}
public static function escape($str) {
- switch (self::$driver) {
- case 'pdo':
- return substr(@self::$connection->quote($str, PDO::PARAM_STR), 1, -1);
- case 'mysqli':
- return @self::$connection->real_escape_string($str);
+ if (self::$connected) {
+ switch (self::$driver) {
+ case 'pdo':
+ return substr(@self::$connection->quote($str, PDO::PARAM_STR), 1, -1);
+ case 'mysqli':
+ return @self::$connection->real_escape_string($str);
+ }
+ } else {
+ return str_replace("'", "\\'", $str);
}
}
switch (self::$driver) {
case 'pdo':
$r = self::p("SELECT 1");
- if (self::is_result($r)) {
+ if (self::isResult($r)) {
$row = self::toArray($r);
$connected = ($row[0]['1'] == '1');
}
$commands[$key] = ['table' => $table, 'conditions' => $conditions];
- $cascade = defaults($options, 'cascade', true);
+ // Don't use "defaults" here, since it would set "false" to "true"
+ if (isset($options['cascade'])) {
+ $cascade = $options['cascade'];
+ } else {
+ $cascade = true;
+ }
// To speed up the whole process we cache the table relations
if ($cascade && count(self::$relation) == 0) {
*
* @return boolean Whether $array is a filled array or an object with rows
*/
- public static function is_result($array)
+ public static function isResult($array)
{
// It could be a return value from an update statement
if (is_bool($array)) {
* @param boolean $add_quotation add quotation marks for string values
* @return void
*/
- private static function esc_array_callback(&$value, $key, $add_quotation)
+ private static function escapeArrayCallback(&$value, $key, $add_quotation)
{
if (!$add_quotation) {
if (is_bool($value)) {
$value = ($value ? '1' : '0');
} else {
- $value = dbesc($value);
+ $value = self::escape($value);
}
return;
}
} elseif (is_float($value) || is_integer($value)) {
$value = (string) $value;
} else {
- $value = "'" . dbesc($value) . "'";
+ $value = "'" . self::escape($value) . "'";
}
}
* @param boolean $add_quotation add quotation marks for string values
* @return void
*/
- public static function esc_array(&$arr, $add_quotation = false)
+ public static function escapeArray(&$arr, $add_quotation = false)
{
- array_walk($arr, 'self::esc_array_callback', $add_quotation);
+ array_walk($arr, 'self::escapeArrayCallback', $add_quotation);
}
}