Exemple #1
0
            /// <summary>
            /// Deserializes a graph of connected object from a byte array using a given formatter.
            /// </summary>
            /// <param name="ctx">Runtime context.</param>
            /// <param name="data">The string to deserialize the graph from.</param>
            /// <param name="caller">Caller's class context.</param>
            /// <returns>The deserialized object graph or <B>false</B> on error.</returns>
            public PhpValue Deserialize(Context ctx, PhpString data, RuntimeTypeHandle caller /*, allowed_classes */)
            {
                var stream = new MemoryStream(data.ToBytes(ctx));

                try
                {
                    return(CommonDeserialize(ctx, stream, caller));
                }
                catch (Spl.Exception)
                {
                    throw;
                }
                catch (Exception e)
                {
                    PhpException.Throw(PhpError.Notice, LibResources.deserialization_failed, e.Message, stream.Position.ToString(), stream.Length.ToString());
                    return(PhpValue.False);
                }
            }
Exemple #2
0
            public PhpString Replace(Context ctx, PhpString subject, int limit, ref long count)
            {
                var oldcount = count;
                var newvalue = Evaluator != null
                    ? Regex.Replace(subject.ToString(ctx), Evaluator, (int)limit, ref count)
                    : Regex.Replace(subject.ToString(ctx), Replacement, (int)limit, ref count);

                if (oldcount != count)
                {
                    subject = newvalue; // NOTE: possible corruption of 8bit string
                }
                else
                {
                    // - workaround for https://github.com/peachpiecompiler/peachpie/issues/178
                    // - use the original value if possible
                }

                return(subject);
            }
Exemple #3
0
        /// <summary>
        /// Send data in blocks.
        /// </summary>
        public bool send_long_data(int param_nr, PhpString data)
        {
            if (param_nr >= 0 && _bound_params_type != null && param_nr < _bound_params_type.Length)
            {
                if (_bound_params_type[param_nr] == BoundType.Blob)
                {
                    //
                    var alias = _bound_params[param_nr];
                    var str   = alias.ToPhpString(this.Connection.Context);
                    str.EnsureWritable().Add(data);
                    alias.Value = str;

                    return(true);
                }
            }

            // ERR
            return(false);
        }
Exemple #4
0
        public static PhpResource mysql_query(Context ctx, PhpString query, PhpResource link = null)
        {
            var connection = ValidConnection(ctx, link);

            if (connection == null || query.IsEmpty)
            {
                return(null);
            }
            else if (query.ContainsBinaryData)
            {
                // be aware of binary data
                return(QueryBinary(ctx.StringEncoding, query.ToBytes(ctx), connection));
            }
            else
            {
                // standard unicode behaviour
                return(connection.ExecuteQuery(query.ToString(ctx), true));
            }
        }
Exemple #5
0
        /// <summary>
        /// Takes a JSON encoded string and converts it into a PHP variable.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="json"></param>
        /// <param name="assoc">When TRUE, returned object's will be converted into associative array s. </param>
        /// <param name="depth">User specified recursion depth. </param>
        /// <param name="options"></param>
        /// <returns>Returns the value encoded in json in appropriate PHP type. Values true, false and null are returned as TRUE, FALSE and NULL respectively. NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.</returns>
        public static PhpValue json_decode(Context ctx, PhpString json, bool assoc = false, int depth = 512, JsonDecodeOptions options = JsonDecodeOptions.Default)
        {
            if (json.IsEmpty)
            {
                return(PhpValue.Null);
            }

            var decodeoptions = new PhpSerialization.JsonSerializer.DecodeOptions()
            {
                Depth   = depth,
                Options = options,
            };

            if (assoc)
            {
                decodeoptions.Options |= JsonDecodeOptions.JSON_OBJECT_AS_ARRAY;
            }

            return(new PhpSerialization.JsonSerializer(decodeOptions: decodeoptions).Deserialize(ctx, json, default));
        }
Exemple #6
0
        /// <summary>
        /// Gets substring of this instance.
        /// The operation safely maintains single byte and unicode characters, and reuses existing underlaying chunks of text.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">The start index is less than zero.</exception>
        public static PhpString Substring(this PhpString str, int startIndex, int length)
        {
            if (str.IsDefault || length < 0)
            {
                return(default(PhpString)); // FALSE
            }

            if (length == 0)
            {
                return(new PhpString(string.Empty));
            }

            //

            var blob = new PhpString.Blob();

            str.CopyTo(blob, startIndex, length);

            return(new PhpString(blob));
        }
Exemple #7
0
        public static string iconv_substr(Context ctx, PhpString str, int offset, int length = int.MaxValue /*= iconv_strlen($str, $charset)*/, string charset = null /*= ini_get("iconv.internal_encoding")*/)
        {
            if (str.IsEmpty)
            {
                return(null);
            }

            if (str.ContainsBinaryData)
            {
                // encoding matters

                var encoding = ResolveEncoding(ctx, charset);
                if (encoding == null)
                {
                    throw new NotSupportedException("charset not supported");                   // TODO: PHP friendly warning
                }
                return(Strings.substr(str.ToString(encoding), offset, length).ToString(ctx));
            }

            return(Strings.substr(str.ToString(ctx), offset, length).ToString(ctx));
        }
Exemple #8
0
        //iconv_mime_decode_headers — Decodes multiple MIME header fields at once
        //iconv_mime_decode — Decodes a MIME header field
        //iconv_mime_encode — Composes a MIME header field

        /// <summary>
        /// Returns the character count of string.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="str">The string.</param>
        /// <param name="charset">If charset parameter is omitted, <paramref name="str"/> is assumed to be encoded in iconv.internal_encoding.</param>
        /// <returns>Returns the character count of str, as an integer.</returns>
        public static int iconv_strlen(Context ctx, PhpString str, string charset = null /*=iconv.internal_encoding*/)
        {
            if (str.IsEmpty)
            {
                return(0);
            }

            if (str.ContainsBinaryData)
            {
                var encoding = ResolveEncoding(ctx, charset);
                if (encoding == null)
                {
                    throw new NotSupportedException("charset not supported");                   // TODO: PHP friendly warning
                }
                return(encoding.GetCharCount(str.ToBytes(ctx)));
            }
            else
            {
                return(str.Length);
            }
        }
Exemple #9
0
        public void Reverse()
        {
            //
            TestReverse("hello", "olleh");
            TestReverse("", "");
            TestReverse(new PhpString(new byte[] { 0, 1, 2, 3 }), new PhpString(new byte[] { 3, 2, 1, 0 }));

            // complex string
            var str = new PhpString("hello");

            str.EnsureWritable().Add(new byte[] { 1, 2, 3 });
            str.EnsureWritable().Add("world");

            var reversed = new PhpString();

            reversed.EnsureWritable().Add("dlrow");
            reversed.EnsureWritable().Add(new byte[] { 3, 2, 1 });
            reversed.EnsureWritable().Add("olleh");

            TestReverse(str, reversed);
        }
Exemple #10
0
        /// <summary>
        /// Binary-safe file write implementation.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="handle">The file stream (opened for writing). </param>
        /// <param name="data">The data to be written.</param>
        /// <param name="length">The number of characters to write or <c>-1</c> to use the whole <paramref name="data"/>.</param>
        /// <returns>Returns the number of bytes written, or FALSE on error. </returns>
        static int WriteInternal(Context ctx, PhpResource handle, PhpString data, int length)
        {
            var stream = PhpStream.GetValid(handle);

            if (stream == null)
            {
                return(-1);
            }

            if (data.IsEmpty)
            {
                return(0);
            }

            // Note: Any data type is converted using implicit conversion in AsText/AsBinary.
            if (stream.IsText)
            {
                // If file OpenMode is text then use string access methods.
                var sub = data.ToString(ctx);
                if (length > 0 && length < sub.Length)
                {
                    sub = sub.Remove(length);
                }

                return(stream.WriteString(sub));
            }
            else
            {
                // File OpenMode is binary.
                byte[] sub = data.ToBytes(ctx);
                if (length > 0 && length < sub.Length)
                {
                    var bytes = new byte[length];
                    Array.Copy(sub, bytes, length);
                    sub = bytes;
                }

                return(stream.WriteBytes(sub));
            }
        }
Exemple #11
0
        //public static int poll(array &$read , array &$error , array &$reject , int $sec[, int $usec] )
        //mysqli_stmt prepare(string $query )

        /// <summary>
        /// Performs a query on the database.
        /// </summary>
        /// <returns>
        /// Returns FALSE on failure.
        /// For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object.
        /// For other successful queries mysqli_query() will return TRUE</returns>
        public PhpValue query(PhpString query, int resultmode = Constants.MYSQLI_STORE_RESULT)
        {
            MySqlResultResource result;

            if (query.ContainsBinaryData)
            {
                var encoding = _connection.Context.StringEncoding;

                // be aware of binary data
                result = (MySqlResultResource)MySql.QueryBinary(encoding, query.ToBytes(encoding), _connection);
            }
            else
            {
                // standard unicode behaviour
                result = (MySqlResultResource)_connection.ExecuteQuery(query.ToString(Encoding.UTF8 /*not used*/), true);
            }


            if (result != null)
            {
                insert_id = result.Command.LastInsertedId;

                if (result.FieldCount == 0)
                {
                    // no result set => not a SELECT
                    result.Dispose();
                    return(PhpValue.True);
                }

                // TODO: resultmode

                return(PhpValue.FromClass(new mysqli_result(result)));
            }
            else
            {
                return(PhpValue.False);
            }
        }
Exemple #12
0
 public override void Accept(PhpString obj)
 {
     Accept(obj.ToBytes(this.Encoding));
 }
Exemple #13
0
 public bool write(string session_id, PhpString session_data) => (bool)_write.Invoke(_ctx, (PhpValue)session_id, PhpValue.Create(session_data));
Exemple #14
0
 public virtual void unserialize(PhpString serialized) =>
 __unserialize(StrictConvert.ToArray(PhpSerialization.unserialize(_ctx, default, serialized)));
Exemple #15
0
                /// <summary>
                /// Parses the <B>O</B> and <B>C</B> tokens.
                /// </summary>
                /// <param name="serializable">If <B>true</B>, the last token eaten was <B>C</B>, otherwise <B>O</B>.</param>
                object ParseObject(bool serializable)
                {
                    Debug.Assert(_ctx != null);

                    var seq = AddSeq();

                    // :{length}:"{classname}":
                    Consume(Tokens.Colon);                       // :
                    string class_name = ReadString().AsString(); // <length>:"classname"
                    var    tinfo      = _ctx?.GetDeclaredType(class_name, true);

                    // :{count}:
                    Consume(Tokens.Colon);  // :
                    var count = (unchecked ((int)ReadInteger()));

                    if (count < 0)
                    {
                        ThrowInvalidLength();
                    }
                    Consume(Tokens.Colon);

                    // bind to the specified class
                    object obj;

                    if (tinfo != null)
                    {
                        obj = tinfo.CreateUninitializedInstance(_ctx);
                        if (obj == null)
                        {
                            throw new ArgumentException(string.Format(LibResources.class_instantiation_failed, class_name));
                        }
                    }
                    else
                    {
                        // TODO: DeserializationCallback
                        // __PHP_Incomplete_Class
                        obj = new __PHP_Incomplete_Class();
                        throw new NotImplementedException("__PHP_Incomplete_Class");
                    }

                    // {
                    Consume(Tokens.BraceOpen);

                    if (serializable)
                    {
                        // check whether the instance is PHP5.1 Serializable
                        if (!(obj is global::Serializable))
                        {
                            throw new ArgumentException(string.Format(LibResources.class_has_no_unserializer, class_name));
                        }

                        PhpString serializedBytes;
                        if (count > 0)
                        {
                            // add serialized representation to be later passed to unserialize
                            var buffer = new byte[count];
                            if (_stream.Read(buffer, 0, count) < count)
                            {
                                ThrowEndOfStream();
                            }

                            serializedBytes = new PhpString(buffer);
                        }
                        else
                        {
                            serializedBytes = PhpString.Empty;
                        }

                        // Template: Serializable::unserialize(data)
                        ((global::Serializable)obj).unserialize(serializedBytes);
                    }
                    else
                    {
                        var __unserialize       = tinfo.RuntimeMethods[TypeMethods.MagicMethods.__unserialize];
                        var __unserialize_array = __unserialize != null ? new PhpArray(count) : null;

                        // parse properties
                        while (--count >= 0)
                        {
                            var key   = Parse();
                            var value = Parse();

                            //
                            if (key.TryToIntStringKey(out var iskey))
                            {
                                if (__unserialize_array != null)
                                {
                                    __unserialize_array[iskey] = value;
                                }
                                else
                                {
                                    // set property
                                    SetProperty(obj, tinfo, iskey.ToString(), value, _ctx);
                                }
                            }
                            else
                            {
                                this.ThrowInvalidDataType();
                            }
                        }

                        if (__unserialize != null)
                        {
                            __unserialize.Invoke(_ctx, obj, __unserialize_array);
                        }
                        else
                        {
                            // __wakeup
                            var __wakeup = tinfo.RuntimeMethods[TypeMethods.MagicMethods.__wakeup];
                            if (__wakeup != null)
                            {
                                __wakeup.Invoke(_ctx, obj);
                            }
                        }
                    }

                    // }
                    Consume(Tokens.BraceClose);

                    //
                    seq.Value = PhpValue.FromClass(obj);
                    return(obj);
                }
Exemple #16
0
 public override void Accept(PhpString obj)
 {
     _output.Append("'");
     _output.Append(obj);
     _output.Append("'");
 }
Exemple #17
0
 public override void Accept(PhpString obj) => _output.Append(obj);
Exemple #18
0
 /// <summary>
 /// Creates a PHP value from a stored representation.
 /// </summary>
 /// <param name="ctx">Runtime context.</param>
 /// <param name="caller">Class context.</param>
 /// <param name="str">The serialized string.</param>
 /// <param name="options">Any options to be provided to unserialize(), as an associative array.</param>
 /// <returns>
 /// The converted value is returned, and can be a boolean, integer, float, string, array or object.
 /// In case the passed string is not unserializeable, <c>FALSE</c> is returned and <b>E_NOTICE</b> is issued.
 /// </returns>
 public static PhpValue unserialize(Context ctx, [ImportCallerClass] RuntimeTypeHandle caller, PhpString str, PhpArray options = null)
 {
     return(PhpSerializer.Instance.Deserialize(ctx, str, caller));
 }
Exemple #19
0
 public override void Accept(PhpString obj)
 {
     WriteString(obj.ToString(_ctx));
 }
Exemple #20
0
 /// <summary>
 /// Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.
 /// </summary>
 public static PhpString mysqli_real_escape_string(mysqli link, PhpString escapestr) => link.real_escape_string(escapestr);
Exemple #21
0
                /// <summary>
                /// Parses the <B>O</B> and <B>C</B> tokens.
                /// </summary>
                /// <param name="serializable">If <B>true</B>, the last token eaten was <B>C</B>, otherwise <B>O</B>.</param>
                object ParseObject(bool serializable)
                {
                    // :{length}:"{classname}":
                    Consume(Tokens.Colon);                       // :
                    string class_name = ReadString().AsString(); // <length>:"classname"
                    var    tinfo      = _ctx.GetDeclaredType(class_name, true);

                    // :{count}:
                    Consume(Tokens.Colon);  // :
                    var count = (unchecked ((int)ReadInteger()));

                    if (count < 0)
                    {
                        ThrowInvalidLength();
                    }
                    Consume(Tokens.Colon);

                    // bind to the specified class
                    object obj;

                    if (tinfo != null)
                    {
                        obj = tinfo.GetUninitializedInstance(_ctx);
                        if (obj == null)
                        {
                            throw new ArgumentException(string.Format(LibResources.class_instantiation_failed, class_name));
                        }
                    }
                    else
                    {
                        // TODO: DeserializationCallback
                        // __PHP_Incomplete_Class
                        obj = new __PHP_Incomplete_Class();
                        throw new NotImplementedException("__PHP_Incomplete_Class");
                    }

                    Consume(Tokens.BraceOpen);

                    if (serializable)
                    {
                        // check whether the instance is PHP5.1 Serializable
                        if (!(obj is global::Serializable))
                        {
                            throw new ArgumentException(string.Format(LibResources.class_has_no_unserializer, class_name));
                        }

                        PhpString serializedBytes;
                        if (count > 0)
                        {
                            // add serialized representation to be later passed to unserialize
                            var buffer = new byte[count];
                            if (_stream.Read(buffer, 0, count) < count)
                            {
                                ThrowEndOfStream();
                            }

                            serializedBytes = new PhpString(buffer);
                        }
                        else
                        {
                            serializedBytes = PhpString.Empty;
                        }

                        // Template: Serializable::unserialize(data)
                        ((global::Serializable)obj).unserialize(serializedBytes);
                    }
                    else
                    {
                        // parse properties
                        while (--count >= 0)
                        {
                            // parse property name
                            var nameval = Parse();
                            var pname   = nameval.ToStringOrNull();
                            if (pname == null)
                            {
                                if (!nameval.IsInteger())
                                {
                                    ThrowInvalidDataType();
                                }
                                pname = nameval.ToStringOrThrow(_ctx);
                            }

                            // parse property value
                            var pvalue = Parse();

                            // set property
                            SetProperty(obj, tinfo, pname, pvalue, _ctx);
                        }

                        // __wakeup
                        var __wakeup = tinfo.RuntimeMethods[TypeMethods.MagicMethods.__wakeup];
                        if (__wakeup != null)
                        {
                            __wakeup.Invoke(_ctx, obj);
                        }
                    }

                    Consume(Tokens.BraceClose);

                    //
                    return(obj);
                }
Exemple #22
0
        static PhpString PregReplaceInternal(Context ctx, PatternAndReplacement[] regexes, PhpString subject, long limit, ref long count)
        {
            for (int i = 0; i < regexes.Length; i++)
            {
                subject = regexes[i].Replace(ctx, subject, (int)limit, ref count);
            }

            //
            return(subject);
        }
Exemple #23
0
 /// <summary>
 /// Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.
 /// </summary>
 public PhpString escape_string(PhpString escapestr) => real_escape_string(escapestr);
Exemple #24
0
 public static string base64_encode(Context ctx, PhpString data_to_encode)
 {
     return(System.Convert.ToBase64String(data_to_encode.ToBytes(ctx.StringEncoding)));
 }
Exemple #25
0
 public virtual bool write(string session_id, PhpString session_data)
 {
     throw new NotImplementedException();
 }
Exemple #26
0
        /// <summary>
        /// Unpacks data from a string of bytes into <see cref="PhpArray"/>.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="format">The string defining the items of the result. See PHP manual for details.</param>
        /// <param name="data">The string of bytes to be unpacked.</param>
        /// <returns>The <see cref="PhpArray"/> containing unpacked data.</returns>
        public static PhpArray unpack(Context ctx, string format, PhpString data)
        {
            if (format == null)
            {
                return(null);
            }
            byte[] buffer = data.ToBytes(ctx);

            var encoding = ctx.StringEncoding;

            byte[] reversed = new byte[4]; // used for reversing the order of bytes in buffer

            int      i      = 0;
            int      pos    = 0;
            PhpArray result = new PhpArray();

            while (i < format.Length)
            {
                string name;
                int    repeater;
                char   specifier;

                // parses specifier, repeater, and name from the format string:
                ParseFormatToken(format, ref i, out specifier, out repeater, out name);

                int remains = buffer.Length - pos;          // the number of bytes remaining in the buffer
                int size;                                   // a size of data to be extracted corresponding to the specifier

                // repeater of '@' specifier has a special meaning:
                if (specifier == '@')
                {
                    if (repeater > buffer.Length || repeater == InfiniteRepeater)
                    {
                        PhpException.Throw(PhpError.Warning, LibResources.GetString("outside_string", specifier));
                    }
                    else
                    {
                        pos = repeater;
                    }

                    continue;
                }

                // number of operations:
                int op_count;

                // gets the size of the data to read and adjust repeater:
                if (!GetSizeToUnpack(specifier, remains, repeater, out op_count, out size))
                {
                    PhpException.Throw(PhpError.Warning, LibResources.GetString("unknown_format_code", specifier));
                    return(null);
                }

                // repeats operation determined by specifier "op_count" times;
                // if op_count is infinite then stops when the number of remaining characters is zero:
                for (int j = 0; j < op_count || op_count == InfiniteRepeater; j++)
                {
                    if (size > remains)
                    {
                        // infinite means "while data are available":
                        if (op_count == InfiniteRepeater)
                        {
                            break;
                        }

                        PhpException.Throw(PhpError.Warning, LibResources.GetString("not_enought_input", specifier, size, remains));
                        return(null);
                    }

                    PhpValue item;
                    switch (specifier)
                    {
                    case 'X':     // decreases position, no value stored:
                        if (pos == 0)
                        {
                            PhpException.Throw(PhpError.Warning, LibResources.GetString("outside_string", specifier));
                        }
                        else
                        {
                            pos--;
                        }
                        continue;

                    case 'x':     // advances position, no value stored
                        pos++;
                        continue;

                    case 'a':     // NUL-padded string
                    case 'A':     // SPACE-padded string
                    {
                        byte pad = (byte)(specifier == 'a' ? 0x00 : 0x20);

                        int last = pos + size - 1;
                        while (last >= pos && buffer[last] == pad)
                        {
                            last--;
                        }

                        item = (PhpValue)encoding.GetString(buffer, pos, last - pos + 1);
                        break;
                    }

                    case 'h':     // Hex string, low/high nibble first - converts to a string, takes n hex digits from string:
                    case 'H':
                    {
                        int p            = pos;
                        int nibble_shift = (specifier == 'h') ? 0 : 4;

                        var sb = StringBuilderUtilities.Pool.Get();
                        for (int k = 0; k < size; k++)
                        {
                            const string hex_digits = "0123456789ABCDEF";

                            sb.Append(hex_digits[(buffer[p] >> nibble_shift) & 0x0f]);

                            // beware of odd repeaters!
                            if (repeater == InfiniteRepeater || repeater > sb.Length)
                            {
                                sb.Append(hex_digits[(buffer[p] >> (4 - nibble_shift)) & 0x0f]);
                            }
                            p++;
                        }

                        item = StringBuilderUtilities.GetStringAndReturn(sb);
                        break;
                    }

                    case 'c':     // signed char
                        item = (PhpValue)(int)unchecked ((sbyte)buffer[pos]);
                        break;

                    case 'C':     // unsigned char
                        item = (PhpValue)(int)buffer[pos];
                        break;

                    case 's':     // signed short (always 16 bit, machine byte order)
                        item = (PhpValue)(int)BitConverter.ToInt16(buffer, pos);
                        break;

                    case 'S':     // unsigned short (always 16 bit, machine byte order)
                        item = (PhpValue)(int)BitConverter.ToUInt16(buffer, pos);
                        break;

                    case 'n':     // unsigned short (always 16 bit, big endian byte order)
                        if (BitConverter.IsLittleEndian)
                        {
                            item = (PhpValue)(int)BitConverter.ToUInt16(LoadReverseBuffer(reversed, buffer, pos, 2), 0);
                        }
                        else
                        {
                            item = (PhpValue)(int)BitConverter.ToUInt16(buffer, pos);
                        }
                        break;

                    case 'v':     // unsigned short (always 16 bit, little endian byte order)
                        if (!BitConverter.IsLittleEndian)
                        {
                            item = (PhpValue)(int)BitConverter.ToUInt16(LoadReverseBuffer(reversed, buffer, pos, 2), 0);
                        }
                        else
                        {
                            item = (PhpValue)(int)BitConverter.ToUInt16(buffer, pos);
                        }
                        break;

                    case 'i':     // signed integer (machine dependent size and byte order - always 32 bit)
                    case 'I':     // unsigned integer (machine dependent size and byte order - always 32 bit)
                    case 'l':     // signed long (always 32 bit, machine byte order)
                    case 'L':     // unsigned long (always 32 bit, machine byte order)
                        item = (PhpValue)BitConverter.ToInt32(buffer, pos);
                        break;

                    case 'N':     // unsigned long (always 32 bit, big endian byte order)
                        item = (PhpValue) unchecked (((int)buffer[pos] << 24) + (buffer[pos + 1] << 16) + (buffer[pos + 2] << 8) + buffer[pos + 3]);
                        break;

                    case 'V':     // unsigned long (always 32 bit, little endian byte order)
                        item = (PhpValue) unchecked (((int)buffer[pos + 3] << 24) + (buffer[pos + 2] << 16) + (buffer[pos + 1] << 8) + buffer[pos + 0]);
                        break;

                    case 'f':     // float (machine dependent size and representation - size is always 4B)
                        item = (PhpValue)(double)BitConverter.ToSingle(buffer, pos);
                        break;

                    case 'd':     // double (machine dependent size and representation - size is always 8B)
                        item = (PhpValue)BitConverter.ToDouble(buffer, pos);
                        break;

                    default:
                        Debug.Fail("Invalid specifier.");
                        return(null);
                    }

                    AddValue(result, name, item, op_count, j);

                    pos     += size;
                    remains -= size;
                }
            }

            return(result);
        }
Exemple #27
0
        public bool more_results() => false; // TODO

        /// <summary>
        /// Performs a query on the database.
        /// </summary>
        public bool multi_query(PhpString query)
        {
            throw new NotImplementedException();
        }
Exemple #28
0
        /// <summary>
        /// Performs a query on the database.
        /// </summary>
        public static PhpValue mysqli_query(mysqli link, PhpString query, int resultmode = Constants.MYSQLI_STORE_RESULT)
        {
            PhpException.ThrowIfArgumentNull(link, 1);

            return(link.query(query, resultmode));
        }
Exemple #29
0
 /// <summary>
 /// Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.
 /// </summary>
 public PhpString real_escape_string(PhpString escapestr) => MySql.mysql_escape_string(_connection.Context, escapestr);
Exemple #30
0
 /// <summary>
 /// Send data in blocks.
 /// </summary>
 public static bool mysqli_stmt_send_long_data(mysqli_stmt stmt, int param_nr, PhpString data) => stmt.send_long_data(param_nr, data);