Exemplo n.º 1
0
 /**
  * void _setLastError($code, $msg, $query)
  * Set last database error context.
  * Aditionally expand placeholders.
  */
 protected function _setLastError($code, $msg, $query)
 {
     if (is_array($query)) {
         $this->_expandPlaceholders($query, false);
         $query = $query[0];
     }
     return parent::_setLastError($code, $msg, $query);
 }
Exemplo n.º 2
0
Arquivo: Json.php Projeto: youhey/Json
 /**
  * PHPの値をJSON形式の文字列に変換
  *
  * <p>PHPのバージョンが5.4.0以上であれば以下の動作に対応</p>
  * <dl>
  * <dt>JSON_UNESCAPED_SLASHES</dt>
  * <dd>"/" をエスケープしない</dd>
  * <dt>JSON_UNESCAPED_UNICODE</dt>
  * <dd>マルチバイト Unicode 文字をそのままの形式で扱う</dd>
  * </dl>
  *
  * @param mixed $data エンコードする値
  *
  * @return string 値をエンコードしたJSON形式の文字列
  *
  * @throws \Json\Exception\Encoding エンコードできないデータが含まれている
  *
  * @see json_encode()
  */
 public static function stringify($data)
 {
     // 性能に影響のない範囲で単純なエンコードのみ自前対応
     if (is_null($data)) {
         return 'null';
     }
     if ($data === true) {
         return 'true';
     }
     if ($data === false) {
         return 'false';
     }
     if ($data === array()) {
         return '[]';
     }
     if ($data === '') {
         return '""';
     }
     if (static::isSupportedOptions()) {
         $encoded = @json_encode($data, self::$encode_option);
     } else {
         $encoded = @json_encode($data);
     }
     if ($encoded !== false) {
         return $encoded;
     }
     $last_error = new LastError();
     if (!$last_error->exists()) {
         return $encoded;
     }
     throw new \Json\Exception\Encoding($last_error);
 }