Thursday 4 January 2018

الخلية الحركة من المتوسط الاستعلام


مشغلات ميسكل: لصناعة السيارات في توليد معلومات إضافية في قاعدة البيانات مشغلات ميسكل هي واحدة من أحدث الميزات في الخلية التي تساعد على جعله بديلا قابلا للتطبيقات المؤسسة الكبيرة. منذ وقت ليس ببعيد، أولئك الذين جعلوا حياتهم باستخدام قواعد البيانات التجارية الكبيرة مثل أوراكل و DB2 أشار إلى أن ميسكل كانت قاعدة بيانات لطيفة وسريعة قليلا ولكنها تفتقر إلى ميزة هامة مثل الإجراءات المخزنة والمعاملات، والمحفزات. اعتبارا من الإصدار 5.0 من ميسكل، هذه الميزات يمكن أن تخرج من تلك القائمة. لذلك، ما هي مشغلات الخلية، ولماذا ميسكلس القدرة على استخدامها تجعلها أكثر جاذبية لمستخدمي قاعدة بيانات خطيرة ببساطة، مشغلات هي البرامج الصغيرة التي يتم تخزينها في قاعدة البيانات نفسها، ويتم تفعيلها من قبل الأحداث قاعدة البيانات التي غالبا ما تنشأ في التطبيق طبقة. هذه الأحداث قاعدة البيانات عجلت هي أوبديت، حذف أو إنزيرت الاستعلامات. قد يتم تنفيذ الزناد نفسه قبل أو بعد الاستعلام الذي يبدأ به. وغالبا ما تستخدم مشغلات للحفاظ على سلامة البيانات عبر جداول التطبيق. عندما يقوم مستخدم على موقع ويب بعملية شراء، على سبيل المثال، قد يكون الإجراء الأول الذي يحدث في قاعدة البيانات هو إدراج ائتمان في جدول محاسبي. عن طريق الزناد هذا الإجراء يمكن أن تبدأ سلسلة من ردود الفعل من الأحداث في الجداول الأخرى في جميع أنحاء التطبيق. يمكن خفض عدد المنتجات لعنصر ما في جدول المخزون، وهو خصم يتم خصمه من رصيد حساب العملاء في جدول آخر، ويتم تطبيق رصيد متجر على جدول آخر. يمكنك أن تقول أنك قمت بذلك طوال الوقت في تطبيقاتك باستخدام فب أو بيرل أو بيثون أو أسب. ماذا يكون صفقة كبيرة حول استخدام ميسكل مشغلات حسنا، هناك بعض المزايا لاستخدام مشغلات على رمز التطبيق للحفاظ على سلامة البيانات عبر الجداول. يؤدي المشغل عموما أنواع المهام الموصوفة بشكل أسرع من رمز التطبيق، ويمكن تنشيطها بسهولة وبسرعة خلف الكواليس ولا يلزم أن تكون جزءا من شفرة التطبيق. هذا يوفر الوقت وقطع الغيار لك من الترميز الزائدة عن الحاجة. إذا كنت من أي وقت مضى ميناء التطبيق الخاص بك إلى لغة أخرى، وهناك احتمالات يمكن أن مشغلات البقاء في مكان دون تعديل، جنبا إلى جنب مع الجداول الخاصة بك وكائنات قاعدة البيانات الأخرى. لإثبات كيفية تشغيل ميسكل العمل، يتيح إعداد جدولين بسيطين على قاعدة بيانات استدعاء جيدا 8220salesrecords8221 التي لديها بيانات مترابطة. تخيل قاعدة بيانات تتتبع سجلات مبيعات ثلاثة مندوبي مبيعات في متجر. وهم يعملون في قسم الإلكترونيات لبيع أشياء مثل أجهزة التلفاز. ستريو، ومشغلات MP3. لدينا الجدول الرئيسي الذي يحتفظ بسجل لكل بيع المقدمة. وتسجل كمية البيع (سالمات) والتاريخ (التاريخ) واسم البائع (الاسم) ورقم معرفه (الموظف)، ومعرف المنتج (بروديد). حسنا استدعاء هذا الجدول (بذكاء بما فيه الكفاية) 8220sales8221. في الجدول الثاني، نريد الاحتفاظ ببعض البيانات التي تسمح لنا بسهولة تتبع كيف يقوم كل مندوب مبيعات. وسيشمل الرقم التعريفي للبائع (الموظف)، والاسم (الاسم)، ومجموع المبيعات (توتالساليس)، والعمود الذي يحافظ على كل متوسط ​​مبيعات للبائعين (أفيسال). نريد أن نرى ووس تتحرك العناصر الراقية. حسنا استدعاء هذا الجدول 8220performance8221. الآن يأتي الجزء الصعب. كما ذكرت، مشغلات هي كائنات قاعدة البيانات تماما كما الجداول. ومع ذلك، يمكن للمشغلات تنفيذ التعليمات البرمجية الإجرائية التي تعدل البيانات في الجداول الخاصة بك. في هذه الحالة، نرغب في تشغيل المشغل قبل أي بيان إنزيرت الذي ينفذ في جدول المبيعات. عند إدراج سجل بيع في جدول المبيعات، يجب تحديث مجاميع المبيعات في جدول الأداء. يمكن كتابة التعليمات البرمجية التالية في محرر النص المفضل لديك ولصق في كونسول الخاص بك في موجه ميسكل. قبل أن تفعل ذلك على الرغم من ذلك، تريد تنفيذ هذا الخط: لدينا التعليمات البرمجية الإجرائية يستخدم الفاصلة المنقوطة في نهاية البيانات، لذلك نحن بحاجة إلى تعيين محدد مختلف للسماح ميسكل معرفة عندما انتهت كتلة التعليمات البرمجية لدينا، وحتى أنه لا يتوقف عن معالجة كتلة لدينا عندما يضرب فاصلة منقوطة. نضع في اعتبارنا أنه بعد الانتهاء من كتلة الخاص بك سيكون لديك لتعيين محدد مرة أخرى إلى الفاصلة المنقوطة، أو إنهاء أي أوامر لاحقة مع محدد جديد. على سبيل المثال إذا قمت بإجراء أخطاء في كتلة تريجر تريجر الخاص بك وتريد حذفه، دروب تريجر لن تعمل إلا إذا قمت بتعيين محدد مرة أخرى إلى الفاصلة المنقوطة. هنا هو رمز لالزناد: موافق، يتيح الحديث عن رمز. باستخدام عبارة كريت تريجر، بدأنا الزناد، تسمية ذلك ساليسبترغ. مشغلات الخلية يمكن اطلاق النار قبل أو بعد إدراج، تحديث أو حذف الحدث. هذا الحرائق واحد قبل إدراج أي بيانات في جدول المبيعات. تعني عبارة "لكل حالة" أن الكتلة ستعمل على كل صف يلبي معايير عبارات سكل. تحتوي الكلمات الرئيسية بيجين و إند على عبارات التشغيل التي سيتم تنفيذها عند إطلاق المشغل. هناك نوعان من المتغيرات المعلنة. الأول هو نومرو الذي يتحقق لمعرفة ما إذا كان الموظف الذي قام بعملية البيع التي سيتم إدخالها، وكان قد تم بيعها في جدول الأداء سابقا. إذا لم يكن هناك موظفون يتطابقون، فهذا هو بيع الموظفين لأول مرة، وهذا يلبي شرط إلس في بياننا 8220IF. سيتم إدخال هذه البيانات كإدراج في جدول الأداء بدلا من تحديث. إذا كان نومرو أكبر من 0، ثم سيتم تحديث جدول الأداء. المتغير الثاني، توتروس، هو عدد كم المبيعات الموظف في جدول المبيعات. يتم استخدام هذه القيمة لحساب متوسط ​​مبيعات الموظفين. ويجري العد قبل أن يتم إدراج البيع في الجدول بيع، لذلك علينا أن نضيف واحد لذلك. عندما يتم تحديث جدول الأداء متوسط ​​المبيعات الإجمالية (totrows1). إذا كان لدينا الزناد الخلية يعمل بشكل صحيح، فإن جدول الأداء الحفاظ على مجموع تشغيل كل المبيعات إجمالي المبيعات، وأيضا متوسط ​​المبلغ من إجمالي المبيعات. وسوف تفعل هذا بشكل مستقل عن رمز التطبيق الخاص بك وتكون محمولة إلى أي منصة التطبيق. لإعطائها دوامة، إدراج بعض البيانات في جدول المبيعات ومراقبة محتوى جدول الأداء. هنا هو البيان: تغيير الأرقام والأسماء ومحاولة ذلك عدة مرات. (تذكر أن الموظف يحتفظ بنفس رقم الموظف لكل مبيعاته). إذا كنت تشعر بالمغامرة، فابدأ في التفكير في كيفية توسيع مشغل ميسكل ليشمل بيانات أوبديت و ديليت على جدول المبيعات. الكتاب الاليكترونى الحرة الاشتراك في النشرة الإخبارية الخاصة بي والحصول على الكتاب الاليكتروني على الكيان العلاقة مبادئ النمذجة كهدية مجانية: ما يقوله الزوار. أنا فقط تعثرت عبر موقعك تبحث عن بعض نظرية التطبيع، ويجب أن أقول أنه أمر رائع. لقد كنت في مجال قاعدة البيانات لمدة 10 عاما، وأنا لم يأت من قبل عبر مثل هذا الموقع مفيد. شكرا لك على أخذ الوقت لوضع هذا الموقع معا. تقدم فب ثلاث واجهات برمجة تطبيقات مختلفة للاتصال ميسكل. هذه هي ميسكل (إزالتها اعتبارا من فب 7)، ميسكلي. و تمديدات بدو. وظائف ميسكل المستخدمة لتكون شعبية جدا، ولكن لم يتم تشجيع استخدامها بعد الآن. ويناقش فريق التوثيق حالة أمن قاعدة البيانات، وتثقيف المستخدمين على الابتعاد عن تمديد إكستميسكل شائعة الاستخدام هو جزء من هذا (تحقق php. internals: إبطال إكستميسكل). وقد اتخذ فريق المطور فب في وقت لاحق قرار لتوليد أخطاء إديبريكاتد عندما يتصل المستخدمون ميسكل، سواء من خلال ميسكلكونكت (). ميسلكبكونكت () أو وظيفة الاتصال الضمني المضمنة في إكستميسكل. تم إيقاف إكستميسكل رسميا اعتبارا من فب 5.5 وتم إزالتها اعتبارا من فب 7. عندما تذهب في أي صفحة دليل وظيفة ميسكل، ترى مربع أحمر، موضحا أنه لا ينبغي أن تستخدم بعد الآن. التحرك بعيدا عن إكستميسكل ليس فقط حول الأمن، ولكن أيضا عن وجود إمكانية الوصول إلى كافة الميزات من قاعدة بيانات ميسكل. تم بناء إكستميسكل ل ميسكل 3.23 وحصلت فقط عدد قليل جدا من الإضافات منذ ذلك الحين في حين أن معظمهم الحفاظ على التوافق مع هذا الإصدار القديم الذي يجعل رمز أصعب قليلا للحفاظ على. الميزات المفقودة التي لا يدعمها إكستميسكل ما يلي: (من دليل فب). سبب عدم استخدام وظيفة ميسكل: لا تحت التطوير النشط إزالة اعتبارا من فب 7 يفتقر إلى واجهة و لا يدعم غير حجب، استعلامات غير متزامنة لا يدعم البيانات المعدة أو الاستعلامات المعلمة لا يدعم الإجراءات المخزنة لا يدعم بيانات متعددة لا يدعم المعاملات لا يدعم كل من وظيفة في الخلية 5.1 عدم وجود دعم للبيانات المعدة أهمية خاصة لأنها توفر طريقة أكثر وضوحا وأقل عرضة للخطأ الهروب واقتباس البيانات الخارجية من يدويا الهروب منه مع استدعاء وظيفة منفصلة. إلغاء تحذیرات الإھمال بینما یتم تحویل الشفرة إلی ملف بدو ميسكلي. يمكن إبطال الأخطاء إديبريكاتد عن طريق وضع إروربورتينغ في php. ini لاستبعاد إديبريكاتد: لاحظ أن هذا سوف تخفي أيضا تحذيرات الإهمال الأخرى. والتي، مع ذلك، قد تكون لأشياء أخرى غير الخلية. (من دليل فب) وأفضل طريقة هي بدو. وأنا الآن كتابة بدو تعليمي بسيط. A بدو بسيطة وقصيرة تعليمي Q. السؤال الأول في ذهني كان: ما هو بدو A. بدو فب كائنات البيانات هي طبقة الوصول إلى قاعدة البيانات توفير طريقة موحدة للوصول إلى قواعد بيانات متعددة. الاتصال ميسكل مع وظيفة ميسكل أو يمكننا أن نقول أنها الطريقة القديمة (مهملة في فب 5.5 وما فوق) مع شركة تنمية نفط عمان. كل ما عليك القيام به هو إنشاء كائن بدو جديد. يقبل منشئ المعلمات لتحديد مصدر قاعدة البيانات بدو s منشئ يأخذ في الغالب أربعة المعلمات التي هي دسن (اسم مصدر البيانات) واسم المستخدم اختياريا. كلمه السر . هنا أعتقد أنك على دراية كل ما عدا دسن هذا هو جديد في بدو. و دسن هو في الأساس سلسلة من الخيارات التي تخبر بدو التي السائق لاستخدامها، وتفاصيل الاتصال. لمزيد من المرجع، تحقق بدو ميسكل دسن. ملاحظة: يمكنك أيضا استخدام تشارسيتوتف-8. ولكن في بعض الأحيان أنه يسبب خطأ، لذلك من الأفضل استخدام utf8. إذا كان هناك أي خطأ في الاتصال، فإنه سيتم رمي كائن بدوكسيبتيون التي يمكن تخزينها مؤقتا للتعامل مع استثناء أكثر من ذلك. يمكنك أيضا تمرير في العديد من خيارات برنامج التشغيل كمصفوفة للمعلمة الرابعة. أوصي تمرير المعلمة الذي يضع بدو في وضع الاستثناء. لأن بعض السائقين بدو لا تدعم البيانات المعدة محليا، لذلك بدو يؤدي مضاهاة إعداد. كما أنه يتيح لك تمكين هذه المحاكاة يدويا. لاستخدام البيانات المعدة من جانب الخادم الأصلي، يجب تعيينها بشكل خاطئ كاذبة. والآخر هو لإيقاف مضاهاة إعداد الذي يتم تمكينه في برنامج تشغيل ميسكل افتراضيا، ولكن إعداد مضاهاة يجب إيقاف لاستخدام بدو بأمان. وسوف أشرح في وقت لاحق لماذا يجب أن يتم إيقاف إعداد مضاهاة. للعثور على سبب يرجى مراجعة هذا المنصب. هو فقط صالحة للاستعمال إذا كنت تستخدم نسخة قديمة من الخلية التي لا أوصى. وفيما يلي مثال على كيفية القيام بذلك: هل يمكننا تعيين سمات بعد بناء بدو نعم. يمكننا أيضا تعيين بعض السمات بعد بناء بدو مع الأسلوب سيتاتريبوت: معالجة الأخطاء التعامل مع الأخطاء أسهل بكثير في بدو من ميسكل. وهناك ممارسة شائعة عند استخدام ميسكل هو: أو يموت () ليست وسيلة جيدة للتعامل مع الخطأ لأننا لا يمكن التعامل مع الشيء في يموت. وسوف تنتهي فقط السيناريو فجأة ثم صدى الخطأ إلى الشاشة التي عادة لا تريد أن تظهر للمستخدمين النهائيين، والسماح للقراصنة دموية اكتشاف المخطط الخاص بك. بدلا من ذلك، غالبا ما يتم استخدام قيم عودة الدالات ميسكل بالاشتراك مع ميسكلورور () لمعالجة الأخطاء. تقدم شركة تنمية نفط عمان حل أفضل: الاستثناءات. أي شيء نقوم به مع بدو يجب أن تكون ملفوفة في محاولة - كتلة الصيد. يمكننا فرض بدو في واحد من ثلاثة أوضاع خطأ عن طريق تعيين السمة وضع الخطأ. هناك ثلاث طرق لمعالجة الأخطاء أدناه. شركة تنمية نفط عمان :: ERRMODESILENT. لها مجرد وضع رموز خطأ ويعمل إلى حد كبير نفس ميسكل حيث يجب عليك التحقق من كل نتيجة ثم ننظر في ديسيبل-غتيرورينفو () للحصول على تفاصيل الخطأ. بدو :: إرموديوارنينغ رفع تحذير. (تحذيرات وقت التشغيل (أخطاء غير مميتة) لا يتم إيقاف تنفيذ البرنامج النصي.) بدو :: إرموديكسسيبتيون. استثناءات رمي. وهو يمثل خطأ أثارته شركة تنمية نفط عمان. يجب عدم رمي بدوكسيبتيون من التعليمات البرمجية الخاصة بك. راجع الاستثناءات للحصول على مزيد من المعلومات حول الاستثناءات في فب. انها تعمل كثيرا مثل أو يموت (ميسكلورور ()). عندما لم يتم القبض عليه. ولكن خلافا أو يموت (). يمكن ضبط بدوكسيبتيون والتعامل معها بأمان إذا اخترت القيام بذلك. ويمكنك التفاف عليه في محاولة - الصيد. مثل أدناه: لم يكن لديك للتعامل مع محاولة - الصيد الآن. يمكنك قبض عليه في أي وقت مناسب، ولكن أوصي بشدة لك لاستخدام محاولة - الصيد. أيضا قد يكون أكثر منطقية للقبض عليه في خارج الدالة التي تدعو الاشياء بدو: أيضا، يمكنك التعامل معها من قبل أو يموت () أو يمكننا أن نقول مثل ميسكل. ولكن سوف تكون متنوعة حقا. يمكنك إخفاء رسائل الخطأ الخطيرة في الإنتاج عن طريق تحويل ديسبلايررز قبالة ومجرد قراءة سجل الخطأ الخاص بك. الآن، بعد قراءة كل الأشياء أعلاه، وربما كنت أفكر: ما هيك هو أنه عندما أريد فقط أن تبدأ يميل بسيط سيليكت. إدراج. تحديث. أو ديليت البيانات لا تقلق، وهنا نذهب: اختيار البيانات لذلك ما تقومون به في ميسكل هو: الآن في بدو. يمكنك أن تفعل هذا مثل: ملاحظة. إذا كنت تستخدم الطريقة مثل أدناه (الاستعلام ())، هذه الطريقة بإرجاع كائن بدوستاتيمنت. حتى إذا كنت ترغب في جلب النتيجة، واستخدامه مثل أعلاه. في بيانات بدو، يتم الحصول عليها عن طريق - gtfetch (). طريقة التعامل مع البيان الخاص بك. قبل استدعاء الجلب، فإن أفضل نهج أن يقول بدو كيف تريد أن يتم جلب البيانات. في القسم أدناه أشرح ذلك. طرق الجلب لاحظ استخدام بدو :: فيتشاسوك في رمز الجلب () و فيتشال () أعلاه. هذا يخبر بدو عن إعادة الصفوف كمصفوفة ارتباطية مع أسماء الحقول كمفاتيح. هناك العديد من وسائط جلب أخرى جدا والتي سوف أشرح واحدا تلو الآخر. أولا وقبل كل شيء، أشرح كيفية تحديد وضع جلب: في أعلاه، لقد تم استخدام جلب (). يمكنك أيضا استخدام: بدوستاتيمنت :: فيتشال () - إرجاع صفيف يحتوي على كافة الصفوف مجموعة النتائج بدوستاتيمنت :: فيتسكولومن () - إرجاع عمود واحد من الصف التالي من مجموعة النتائج بدوستاتيمنت :: فيتشوبجيكت () - جلب الصف التالي وإرجاعه ككائن. بدوستاتيمنت :: سيتفيتشمود () - تعيين وضع جلب الافتراضي لهذا البيان الآن جئت إلى وضع الجلب: بدو :: فيتشاسوك. بإرجاع صفيف مفهرسة باسم العمود كما هو موضح في مجموعة النتائج بدو :: فيتشبوث (افتراضي): بإرجاع صفيف مفهرسة بواسطة كل من اسم العمود ورقم العمود المفهرسة 0 كما تم إرجاعها في مجموعة النتائج هناك المزيد من الخيارات اقرأ كل شيء في وثائق الجلب بدكتوستيمنت. . الحصول على عدد الصف: بدلا من استخدام ميسكلنومروس للحصول على عدد الصفوف التي تم إرجاعها، يمكنك الحصول على بدوستاتيمنت والقيام روكونت (). مثل: الحصول على آخر إدراج معرف إدراج وتحديث أو حذف العبارات ما نقوم به في وظيفة ميسكل هو: وفي بدو، يمكن أن يتم هذا الشيء نفسه من قبل: في الاستعلام أعلاه بدو :: إيكسيك تنفيذ عبارة سكل وإرجاع عدد من الصفوف المتأثرة. سيتم تغطية إدراج وحذف في وقت لاحق. تكون الطريقة المذكورة أعلاه مفيدة فقط عندما لا تستخدم متغير في الاستعلام. ولكن عندما تحتاج إلى استخدام متغير في الاستعلام، لا تحاول من أي وقت مضى مثل ما سبق وهناك لبيان أعدت أو بيان المعلمة هو. البيانات المعدة س: ما هو البيان الذي تم إعداده ولماذا أحتاج إليهم أ. العبارة المعدة عبارة عن عبارة سكل مجمعة مسبقا يمكن تنفيذها عدة مرات عن طريق إرسال البيانات إلى الخادم فقط. سير العمل النموذجي من استخدام بيان أعدت كما يلي (نقلت من ويكيبيديا ثلاثة 3 نقطة): إعداد. يتم إنشاء قالب البيان من قبل التطبيق وإرسالها إلى نظام إدارة قاعدة البيانات (دبمس). يتم ترك بعض القيم غير محددة، تسمى المعلمات أو العناصر النائبة أو ربط المتغيرات (المسمى أدناه): إدراج في المنتج (الاسم والسعر) القيم (.) يقوم نظام إدارة قواعد البيانات بتحليل، تجميع، ويقوم بتحسين الاستعلام على قالب البيان، ويخزن النتيجة دون تنفيذه. نفذ - اعدم . في وقت لاحق، لوازم التطبيق (أو يربط) القيم للمعلمات، و دبمس ينفذ البيان (ربما عائد نتيجة). التطبيق قد تنفيذ البيان عدة مرات كما تريد مع قيم مختلفة. في هذا المثال، قد توفر الخبز للمعلمة الأولى و 1.00 للمعلمة الثانية. يمكنك استخدام بيان تم إعداده من خلال تضمين العناصر النائبة في سكل الخاص بك. هناك أساسا ثلاث منها دون النائبة (لا تحاول هذا مع متغير أعلاه) واحد، مع العناصر النائبة لم يكشف عن اسمه، واحد مع النائبة اسمه. Q. حتى الآن، ما يسمى النائبة وكيف يمكنني استخدامها A. نام المسماة. استخدم أسماء وصفية مسبوقة بنقطتين، بدلا من علامات الاستفهام. نحن لا يهتمون بوسيتوريرر من القيمة في اسم مكان حامل: يمكنك أيضا ربط باستخدام صفيف تنفيذ كذلك: ميزة لطيفة أخرى لأصدقاء أوب هو أن النائبة اسمه لديهم القدرة على إدراج الكائنات مباشرة في قاعدة البيانات الخاصة بك، على افتراض خصائص مطابقة اسمه مجالات. على سبيل المثال: Q. حتى الآن، ما هي العناصر النائبة لم يكشف عن اسمه وكيف يمكنني استخدامها A. يتيح مثالا على ذلك: في ما سبق، يمكنك أن ترى تلك. بدلا من الاسم كما هو الحال في حامل مكان الاسم. الآن في المثال الأول، ونحن تعيين المتغيرات إلى النائبة المختلفة (ستمت-غبيندفالو (1، اسم، بدو :: بارامستر)). ثم نقوم بتخصيص قيم لتلك العناصر النائبة وتنفيذ البيان. في المثال الثاني، يذهب عنصر الصفيف الأول إلى الأول. والثانية إلى الثانية. ملحوظة . في العناصر النائبة التي لم يسمها يجب أن نحرص على الترتيب الصحيح للعناصر في المصفوفة التي نمر بها إلى بدوستاتيمنت :: تنفيذ () الأسلوب. تحديد. إدراج. تحديث. حذف الاستعلامات المعدة أمين، لا، فإنه ليس كذلك. في حين نولبويت حقا فعلت مهمة كبيرة في كتابته، وهذا هو بالتأكيد isn39t قراءة جيدة، لأنه هو وسيلة طويلة. I39m متأكد من أن 8 من 10 زائر ببساطة تخطي ذلك. وكان لديك أيضا تفسير، لماذا هذا الجواب isn39t أعلى صوت. جزء تلدر في البداية سيكون فكرة جيدة، على ما أعتقد. نادش تريجدر يوليو 4 14 في 11:00 أولا، دعونا نبدأ مع تعليق قياسي نعطي الجميع: من فضلك، لا تستخدم وظائف ميسكل في التعليمات البرمجية الجديدة. ولم يعد يحتفظ بها ويتم إهمالها رسميا. انظر المربع الأحمر. تعرف على البيانات المعدة بدلا من ذلك، واستخدام بدو أو ميسكلي - هذه المادة سوف تساعدك على أن تقرر أي. إذا اخترت بدو، وهنا هو تعليمي جيد. دعونا نذهب من خلال هذا، الجملة من الجملة، وشرح: أنها لم تعد محفوظة، ويتم إهمالها رسميا وهذا يعني أن المجتمع فب إسقاط تدريجيا الدعم لهذه الوظائف القديمة جدا. ومن المرجح أن لا وجود لها في المستقبل (الأخيرة) نسخة من فب استمرار استخدام هذه الوظائف قد كسر التعليمات البرمجية الخاصة بك في (ليس ذلك) المستقبل البعيد. تمت إزالة أحدث إكستميسكل في فب 7 بدلا من ذلك، يجب أن تتعلم من البيانات المعدة - تمديد ميسكل لا يدعم البيانات المعدة. وهو (من بين أمور أخرى) مضاد مضادة جدا ضد حقن سكل. انها ثابتة ضعف خطير جدا في التطبيقات المعتمدة الخلية التي تسمح المهاجمين للوصول إلى النص الخاص بك وتنفيذ أي استفسار ممكن على قاعدة البيانات الخاصة بك. عندما تذهب في أي صفحة دليل وظيفة ميسكل، ترى مربع أحمر، موضحا أنه لا ينبغي أن تستخدم بعد الآن. استخدام بدو أو ميسكلي هناك بدائل أفضل وأكثر قوة ومبنية بشكل جيد، بدو - كائن قاعدة بيانات فب. الذي يوفر نهج أوب الكامل لتفاعل قاعدة البيانات، و ميسكلي. وهو تحسين محددة الخلية. سهولة الاستخدام سبق ذكر الأسباب التحليلية والتركيبية. وبالنسبة للقادمين الجدد، فإن الحافز الأكثر أهمية هو التوقف عن استخدام وظائف ميسكل المؤرخة. واجهات برمجة التطبيقات المعاصرة لقاعدة البيانات هي أسهل استخداما. في معظمها المعلمات ملزمة التي يمكن تبسيط التعليمات البرمجية. ومع الدروس الممتازة (كما رأينا أعلاه) الانتقال إلى بدو ليس شاقا بشكل مفرط. إلا أن إعادة كتابة قاعدة شفرة أكبر في آن واحد تستغرق وقتا. رايسون دتر لهذا البديل الوسيط: وظائف بدو المكافئة في مكان ميسكل باستخدام لوت pdomysql. php غ يمكنك التبديل من وظائف ميسكل القديمة مع الحد الأدنى من الجهد. ويضيف بدو مغلفة وظيفة التي تحل محل نظرائهم ميسكل. ببساطة إينلودونس (pdomysql. php) في كل النصي استدعاء أن لديه للتفاعل مع قاعدة البيانات. إزالة بادئة وظيفة ميسكل في كل مكان واستبدالها مع بدو. (يصبح) بدو فيتشاراي () ميسكل فيتشاسوك () يصبح يصبح بدو كونيكت () يصبح بدو كونيكت () ميسكل كيري () بدو كيري () ميسكل نومروز () بدو فيتشاسوك () ميسكل ريلسكابسترينغ () يصبح بدو ريلسكابسترينغ () وهلم جرا. سوف تعمل التعليمات البرمجية على حد سواء ولا تزال تبدو في الغالب نفسه: إت فويل. التعليمات البرمجية الخاصة بك تستخدم بدو. الآن وقتها لاستخدامها في الواقع. يمكن أن تكون المعلمات ملزمة سهلة الاستخدام تحتاج فقط أبي أقل غير عملي. بدوكيري () يضيف دعم فاسيلي جدا للمعلمات ملزمة. تحويل التعليمات البرمجية القديمة مباشرة: نقل المتغيرات الخاصة بك من سلسلة سكل. قم بإضافتها كمعلمات وظيفة محددة بفواصل إلى بدوكيري (). ضع علامات الاستفهام. كما النائبة حيث المتغيرات كانت من قبل. تخلص من يقتبس واحد أن القيم المغلقة سلسلة القيم سابقا. تصبح الميزة أكثر وضوحا للرمز الأطول. في كثير من الأحيان المتغيرات سلسلة أرينت فقط استقراء في سكل، ولكن متسلسلة مع الهروب المكالمات بينهما. مع. تطبيق النائبة لك لا تضطر إلى عناء مع ذلك: تذكر أن بدو لا يزال يسمح إما أو. فقط لا الهروب متغير وربط ذلك في نفس الاستعلام. يتم توفير ميزة العنصر النائب من قبل بدو حقيقية وراء ذلك. وهكذا سمح أيضا: اسمه قوائم النائب في وقت لاحق. الأهم من ذلك يمكنك تمرير متغيرات طلب بأمان وراء أي استفسار. عندما حقول لوفتفغت المقدمة تطابق بنية قاعدة البيانات بالضبط حتى أقصر: الكثير من البساطة. ولكن دعونا نعود إلى بعض المشورة أكثر إعادة كتابة والأسباب التقنية لماذا قد ترغب في التخلص من ميسكل والهروب. إصلاح أو إزالة أي تعقيم أولدشول () وظيفة بمجرد تحويل جميع المكالمات ميسكل إلى بدوكيري مع معلمات ملزمة، وإزالة كافة المكالمات بدورياليسكابسترينغ زائدة عن الحاجة. على وجه الخصوص يجب عليك إصلاح أي تعقيم أو تنظيف أو تصفية هذه أو وظائف كليانداتا كما تم الإعلان عنها من قبل دروس مؤرخة في شكل واحد أو آخر: معظم الخلل الصارخ هنا هو عدم وجود وثائق. والأهم من ذلك هو أن الترشيح كان في الترتيب الخطأ. كان من الصحيح أن يكون: ستريبسلاشيس ديبريكاتدلي كدعوة الأعمق، ثم تقليم. بعد ذلك. هتملنتيتيز لإطار الإخراج، وفقط أخيرا إسكابيسترينغ كتطبيقه يجب مباشرة قبل إنتيرسبارسينغ سكل. ولكن كخطوة أولى مجرد التخلص من دعوة رياليسكابيسترينغ. قد تضطر إلى الحفاظ على بقية الخاص تعقيم () وظيفة في الوقت الراهن إذا كان قاعدة البيانات وتدفق التطبيق يتوقع هتمل السياق السياق سلاسل. إضافة تعليق أنه ينطبق فقط هتمل الهروب من الآن فصاعدا. يتم تفويض التعامل مع سترينغفالو ل بدو والبيانات الخاصة به المعلمة. إذا كان هناك أي ذكر ل ستريبسلاشيس () في وظيفة التعقيم الخاص بك، فإنه قد يشير إلى مستوى أعلى من الرقابة. كان هذا عادة هناك للتراجع عن الضرر (مزدوجة الهروب) من سحرية تم إهمالها. والتي هي أفضل ثابتة مركزيا. لا سلسلة بواسطة سلسلة. استخدام أحد النهج عكس أوسيرلاند. ثم إزالة ستريبسلاشيس () في وظيفة تعقيم. مذكرة تاريخية عن سحرية. تم إيقاف هذه الميزة بشكل صحيح. في كثير من الأحيان يصور بشكل غير صحيح كما فشل ميزة الأمن. ولكن سحرية هي كما فشلت ميزة أمنية كما كرات التنس قد فشلت كمصدر التغذية. هذا ببساطة لم يكن الغرض منها. تنفيذ الأصلي في PHP2FI عرضه بشكل واضح مع مجرد يقتبس سيتم هرب تلقائيا مما يجعل من الأسهل لتمرير بيانات النموذج مباشرة إلى استعلامات مسكل. ومن الجدير بالذكر أنه كان أسيدنتيالي آمنة للاستخدام مع مسكل. كما أن دعم أسي فقط. ثم إعادة إدخال PHP3Zend ماجيككوتس ل ميسكل و ميسدوكومنتيد ذلك. ولكن في الأصل كان مجرد ميزة الراحة. لا تنوي الأمن. كيف تتغير البيانات المعدة عند التدافع سلسلة المتغيرات في استعلامات سكل، فإنه لا مجرد الحصول على أكثر تعقيدا بالنسبة لك لمتابعة. أيضا جهد خارجي ل ميسكل لفصل التعليمات البرمجية والبيانات مرة أخرى. حقن سكل ببساطة عندما ينزف البيانات في سياق التعليمات البرمجية. خادم قاعدة بيانات لا يمكن لاحقا بقعة حيث فب أصلا لصقها متغيرات في الاستعلام بين بنود. مع المعلمات ملزمة لك فصل التعليمات البرمجية سكل وقيم سياق سكل في التعليمات البرمجية فب الخاص بك. ولكن لا يحصل تعديلا مرة أخرى وراء الكواليس (إلا مع بدو :: إمولاتيبريباريس). تتلقى قاعدة البيانات الخاصة بك أوامر سكل غير المتغيرة وقيم متغير 1: 1. في حين أن هذه الإجابة تؤكد أن عليك أن تهتم بمزايا القراءة من إسقاط ميسكل. ثريس في بعض الأحيان أيضا ميزة الأداء (تكرار إنزيرتس مع قيم مختلفة فقط) بسبب هذا الفصل داتاكود الفنية والتقنية. حذار أن المعلمة ملزمة لا يزال هو الحل السحر وقفة واحدة ضد جميع حقن سكل. فإنه يعالج الاستخدام الأكثر شيوعا ل داتافالويس. ولكن غير قادر على إضافة معرفات جدول اسم العمود البيضاء، أو المساعدة في إنشاء بند ديناميكي، أو قوائم قيمة صفيف عادي. استخدام بدو الهجين هذه الوظائف بدو المجمع جعل أبي توقف الفجوة ودية الترميز. (لها إلى حد كبير ما ميسكلي يمكن أن يكون لو كان واسنت لوظيفة التوقيع الفقهي وظيفة). كما أنها تعرض بدو حقيقية في معظم الأحيان. إعادة كتابة لا يجب أن تتوقف عند استخدام أسماء وظيفة بدو جديدة. هل يمكن واحدا تلو الآخر انتقال كل بدويري () إلى عادي بدو إعداد () - تنفيذ () المكالمة. من الأفضل أن تبدأ في تبسيط مرة أخرى. على سبيل المثال جلب النتائج المشتركة: يمكن استبدالها بتكرار فوريش فقط: أو أفضل بعد استرجاع صفيف مباشر وكامل: ستحصل على تحذيرات أكثر فائدة في معظم الحالات من بدو أو ميسكل عادة ما تقدم بعد الاستعلامات الفاشلة. خيارات أخرى لذلك هذا تصور نأمل بعض الأسباب العملية ومسار ورلويل لإسقاط ميسكل. مجرد التحول إلى بدو لا قطع تماما ذلك. بدوكيري () هو أيضا مجرد الواجهة على ذلك. إلا إذا كنت أيضا إدخال معلمة ملزمة أو يمكن الاستفادة من شيء آخر من أبي أجمل، لها مفتاح بلا طائل. آمل أن يصور بسيطا بما فيه الكفاية لعدم زيادة تثبيط الوافدين الجدد. (التعليم عادة ما يعمل بشكل أفضل من الحظر.) في حين أنه مؤهل للحصول على أبسط شيء من ذلك-يمكن-ربما-العمل-فئة العمل، كما لا يزال رمز تجريبي جدا. لقد كتبت للتو في نهاية الأسبوع. ومع ذلك هناك مجموعة كبيرة من البدائل. مجرد جوجل ل فب قاعدة البيانات التجريد وتصفح قليلا. هناك دائما، وسوف يكون الكثير من المكتبات ممتازة لمثل هذه المهام. إذا كنت ترغب في تبسيط التفاعل قاعدة البيانات الخاصة بك أبعد من ذلك، مصممي مثل باريسيدورم تستحق المحاولة. تماما مثل لا أحد يستخدم دوم لطيف في جافا سكريبت بعد الآن، لم يكن لديك لبابيسيت واجهة قاعدة بيانات الخام في الوقت الحاضر. أجاب ديك 24 13 في 23:30 يتحدث عن الأسباب التقنية، وهناك عدد قليل فقط، محددة للغاية ونادرا ما تستخدم. على الأرجح أنك لن تستخدم من أي وقت مضى لهم في حياتك. قد يكون أنا جاهل جدا، ولكن لم يكن لدي فرصة لاستخدامها أشياء مثل غير عرقلة، استعلامات غير متزامنة المخزنة إجراءات العودة ريسولتسيتس متعددة التشفير (سل) ضغط إذا كنت في حاجة إليها - هذه هي الأسباب التقنية لا شك في الابتعاد عن ميسكل تمديد نحو شيء أكثر عصرية وحديثة المظهر. ومع ذلك، هناك أيضا بعض القضايا غير الفنية، والتي يمكن أن تجعل تجربتك قليلا أكثر صعوبة استخدام هذه الوظائف مع إصدارات فب الحديثة رفع إشعارات على مستوى الإهمال. ببساطة يمكن إيقاف. في المستقبل البعيد يمكن إزالتها من بناء فب الافتراضي. ليس صفقة كبيرة جدا، كما سيتم نقل ميدسقل إكست في بيكل وكل المضيف سيكون سعيدا ل كومبلي فب معها، لأنها لا تريد أن تفقد العملاء الذين عملت مواقعهم لعقود. مقاومة قوية من المجتمع ستاكوفيرفلو. في وقت جدا أن أذكر هذه الوظائف الصادقة، يقال لك أنهم تحت محظورة صارمة. كونه متوسط ​​مستخدم فب، على الأرجح فكرتك عن استخدام هذه الوظائف هي عرضة للخطأ والخطأ. فقط بسبب كل هذه الدروس والكتيبات العديدة التي يعلمك بطريقة خاطئة. لا المهام نفسها - لا بد لي من التأكيد على ذلك - ولكن الطريقة التي يتم استخدامها. وهذه المسألة الأخيرة مشكلة. ولكن، في رأيي، الحل المقترح ليس أفضل. يبدو لي مثالية جدا حلم أن جميع المستخدمين فب سوف تتعلم كيفية التعامل مع استعلامات سكل بشكل صحيح في وقت واحد. على الأرجح أنها مجرد تغيير ميسكل إلى ميسكلي ميكانيكيا، وترك النهج نفسه. خاصة لأن ميسكلي يجعل إعداد بيانات جاهزة لا يصدق مؤلمة ومزعجة. ناهيك عن أن البيانات أعدت المحلية يسخر بما فيه الكفاية للحماية من حقن سكل، ولا ميسكلي ولا بدو يقدم حلا. لذلك، بدلا من محاربة هذا التمديد الصريح، إد يفضل مكافحة الممارسات الخاطئة وتثقيف الناس بالطرق الصحيحة. أيضا، هناك بعض الأسباب الكاذبة أو غير الهامة، مثل لا يدعم الإجراءات المخزنة (كنا نستخدم ميسكلكري (كال ميبروك) للأعمار) لا يدعم المعاملات (على النحو الوارد أعلاه) لا تدعم بيانات متعددة (الذين يحتاجون إليها) ليس قيد التطوير النشط (حتى ما يؤثر عليك في أي وسيلة عملية) يفتقر إلى واجهة و (لإنشاء واحد هو مسألة عدة ساعات) لا تدعم البيانات المعدة أو الاستعلامات بارامتريزد واحد الأخير هو نقطة مثيرة للاهتمام. على الرغم من أن ميسكل إكست لا تدعم البيانات أعدت الأصلية، فإنها أرينت المطلوبة للسلامة. يمكننا بسهولة وهمية بيانات أعدت باستخدام النائبة التعامل معها يدويا (تماما مثل شركة تنمية نفط عمان يفعل): فويلا. كل شيء هو بارامتريزد وآمنة. ولكن حسنا، إذا كنت لا تحب المربع الأحمر في الدليل، تنشأ مشكلة الاختيار: ميسكلي أو بدو حسنا، فإن الجواب يكون على النحو التالي: إذا كنت تفهم ضرورة استخدام طبقة تجريد قاعدة البيانات. وتبحث عن أبي لإنشاء واحد، ميسكلي هو خيار جيد جدا، كما أنه يدعم في الواقع العديد من الميزات الخاصة ميسكل. إذا، مثل أغلبية النفايات من الناس فب، كنت تستخدم المكالمات أبي الخام الحق في رمز التطبيق (وهو في الأساس ممارسة خاطئة) - بدو هو الخيار الوحيد. كما يدعي هذا التمديد ليس فقط أبي ولكن بدلا من دال دال، لا يزال غير مكتملة ولكن يقدم العديد من الميزات الهامة، مع اثنين منهم يجعل بدو تميزت بشكل حاد من ميسكلي: على عكس ميسكلي، يمكن أن تربط بدو العناصر النائبة من حيث القيمة. مما يجعل استعلامات بنيت بشكل حيوي ممكن دون عدة شاشات من رمز فوضوي جدا. على عكس ميسكلي، يمكن بدو دائما عودة نتيجة الاستعلام في مجموعة عادية بسيطة، بينما ميسكلي يمكن أن تفعل ذلك فقط على المنشآت ميسكلند. لذلك، إذا كنت مستخدم فب متوسط ​​وتريد أن تنقذ نفسك طن من الصداع عند استخدام البيانات أعدت المحلية، بدو - مرة أخرى - هو الخيار الوحيد. ومع ذلك، بدو ليس رصاصة فضية جدا، ولها صعوبات. لذلك، كتبت حلول لجميع المزالق المشتركة والحالات المعقدة في الوسم بدو الويكي ومع ذلك، الجميع يتحدث عن ملحقات دائما في عداد المفقودين 2 الحقائق الهامة حول ميسكلي و بدو: بيان معدلة ليست رصاصة فضية. هناك معرفات ديناميكية لا يمكن ربطها باستخدام البيانات المعدة. هناك استعلامات ديناميكية مع عدد غير معروف من المعلمات مما يجعل الاستعلام بناء مهمة صعبة. يجب ألا تظهر وظائف ميسكلي ولا بدو في رمز التطبيق. يجب أن يكون هناك طبقة التجريد بينها وبين رمز التطبيق، والتي سوف تفعل كل وظيفة القذرة ملزمة، حلقات، التعامل مع الخطأ، وما إلى ذلك داخل، مما يجعل رمز التطبيق الجاف ونظيفة. خاصة بالنسبة للحالات المعقدة مثل بناء الاستعلام الديناميكي. لذلك، مجرد التبديل إلى بدو أو ميسكلي ليست كافية. على المرء استخدام أورم أو أداة إنشاء استعلام أو أي فئة تجريد قاعدة بيانات بدلا من استدعاء وظائف أبي الخام في التعليمات البرمجية الخاصة بهم. وعلى العكس من ذلك - إذا كان لديك طبقة التجريد بين رمز التطبيق الخاص بك و ميسكل أبي - فإنه لا يهم في الواقع أي محرك يستخدم. يمكنك استخدام ميسكل إكست حتى يذهب يذهب ديبريكاتد ومن ثم إعادة كتابة بسهولة فئة التجريد إلى محرك آخر، وجود كل رمز التطبيق سليمة. وهنا بعض الأمثلة على أساس صفتي سافيميسكل لإظهار كيف يجب أن يكون مثل هذا الطبقة التجريد: قارن هذا سطر واحد واحد مع كمية من التعليمات البرمجية سوف تحتاج مع بدو. ثم قارن مع كمية مجنون من التعليمات البرمجية سوف تحتاج مع الخام ميسكلي إعداد البيانات. لاحظ أن معالجة الأخطاء، والتنميط، تسجيل الاستعلام بنيت بالفعل وتشغيل. قارن مع إدراجات بدو المعتادة، عندما كل اسم حقل واحد يتكرر ستة إلى عشر مرات - في كل هذه العديد من النائبة المسماة، والربط والتعاريف الاستعلام. لا تكاد تجد مثالا لشركة تنمية نفط عمان للتعامل مع هذه الحالة العملية. وسوف تكون وردية جدا وعلى الأرجح غير آمنة. لذلك، مرة أخرى - انها ليست مجرد سائق الخام يجب أن يكون مصدر قلقك ولكن فئة التجريد، مفيدة ليس فقط لأمثلة سخيفة من مبتدئين دليل ولكن على حل أي مشاكل الحياة الحقيقية. كيف لا تكون قيد التطوير النشط فقط لتلك التي تم إنشاؤها 390.0139 إذا كنت بناء شيء مع هذه الوظيفة لا تزال قائمة، تحديث النسخة ميسكل الخاص بك في السنة وينتهي مع نظام غير يعمل، I39m متأكد من وجود الكثير من الناس فجأة في أن 390.0139. I39d يقول أن إهمال وليس تحت التطوير النشط ترتبط ارتباطا وثيقا. يمكنك أن تقول أن هناك كوتنو جدير ريكوتوت لذلك، ولكن الحقيقة هي أنه عندما عرضت الاختيار بين الخيارات، أي تطور نشط يكاد يكون مجرد سيئة كما انكماش I39d يقول نداش نان فبراير 1 13 في 10:21 شاكينتريفونوف: بالتأكيد، فإنه لا تستخدم بيانات أعدت. ولكن لا بدو. والتي يوصي معظم الناس على ميسكلي. لذلك I39m غير متأكد من أن له تأثير كبير هنا. رمز أعلاه (مع أكثر قليلا تحليل) هو ما يقوم به بدو عند إعداد بيان افتراضيا. نداش إرماكسيل 4 فبراير 13 في 12:44 مكتوب هذه الإجابة لإظهار كيف تافهة هو لتجاوز سيئة مكتوبة فب رمز التحقق من صحة المستخدم، وكيف (واستخدام ما) هذه الهجمات العمل وكيفية استبدال وظائف الخلية القديمة مع آمنة بيان أعدت - وأساسا، لماذا المستخدمين ستاكوفيرفلو (ربما مع الكثير من مندوب) ينبح في المستخدمين الجدد طرح الأسئلة لتحسين التعليمات البرمجية الخاصة بهم. أولا، لا تتردد في إنشاء هذه قاعدة بيانات اختبار ميسكل (لقد دعا الألغام الإعدادية): مع أن القيام به، يمكننا الانتقال إلى رمز فب لدينا. لنفترض أن النص البرمجي التالي هو عملية التحقق لأحد المشرفين على موقع ويب (مبسط ولكنه يعمل إذا قمت بنسخه واستخدامه للاختبار): يبدو شرعي بما فيه الكفاية للوهلة الأولى. المستخدم لديه لإدخال تسجيل الدخول وكلمة المرور، والحق بريليانت، لا تدخل في ما يلي: الإخراج هو على النحو التالي: سوبر العمل كما هو متوقع، والآن يتيح محاولة اسم المستخدم وكلمة المرور الفعلية: مذهلة مرحبا-خمسات كل جولة، رمز التحقق بشكل صحيح مشرف. لها الكمال حسنا، ليس حقا. دعونا نقول المستخدم هو شخص ذكي ذكي. دعونا نقول أن الشخص هو لي. أدخل ما يلي: والإخراج هو: مبروك، سمح لي فقط بإدخال المشرفين الخاص بك فائقة المحمية القسم فقط معي إدخال اسم مستخدم كاذبة وكلمة مرور كاذبة. على محمل الجد، إذا كنت لا تصدقني، إنشاء قاعدة البيانات مع رمز قدمته، وتشغيل هذا رمز فب - التي في لمحة يبدو حقا للتحقق من اسم المستخدم وكلمة المرور بدلا لطيف. لذلك، في الإجابة، وهذا هو لماذا كنت يجري يليد أت. لذلك، دعونا نلقي نظرة على ما حدث خطأ، ولماذا أنا فقط حصلت على الخاص بك فائقة المشرف فقط الخفافيش الكهف. أخذت تخمين ويفترض أن كنت ويرنت يجري الحذر مع المدخلات الخاصة بك وببساطة مرت لهم إلى قاعدة البيانات مباشرة. أنا شيدت المدخلات بطريقة ثت من شأنه تغيير الاستعلام الذي كنت قيد التشغيل في الواقع. لذلك، ما كان من المفترض أن يكون، وما الذي انتهى به المطاف هو ثاتس الاستعلام، ولكن عندما نستبدل المتغيرات مع المدخلات الفعلية التي استخدمناها، نحصل على ما يلي: انظر كيف قمت ببناء كلمة المرور الخاصة بي بحيث أنه أولا إغلاق اقتباس واحد حول كلمة المرور، ثم إدخال مقارنة جديدة تماما ثم فقط للسلامة، وأضافت سلسلة أخرى بحيث الاقتباس واحد سوف تحصل مغلقة كما هو متوقع في التعليمات البرمجية كان لدينا أصلا. ومع ذلك، هذا ليس عن الناس يصرخ عليك الآن، وهذا هو عن تبين لك كيفية جعل التعليمات البرمجية الخاصة بك أكثر أمنا. حسنا، لذلك ما حدث خطأ، وكيف يمكننا إصلاحه هذا هو هجوم حقن سكل الكلاسيكية. واحدة من أبسط لهذه المسألة. على نطاق نواقل الهجوم، وهذا هو طفل يهاجم دبابة - والفوز. لذلك، كيف يمكننا حماية القسم الخاص بك المقدسة أدمين وجعلها لطيفة وآمنة أول شيء يجب القيام به هو التوقف عن استخدام تلك الوظائف القديمة حقا وإهمال ميسكل. وأنا أعلم، كنت اتبعت البرنامج التعليمي وجدت على الانترنت وأنها تعمل، ولكن القديمة، التي عفا عليها الزمن وفي الفضاء لبضع دقائق، لقد كسر للتو الماضي من دون الكثير من كسر العرق. الآن، لديك خيارات أفضل لاستخدام ميسكلي أو بدو. أنا شخصيا مروحة كبيرة من بدو، ولذا فإنني سوف تستخدم بدو في بقية هذه الإجابة. هناك إيجابيات وسلبيات، ولكن شخصيا أجد أن الإيجابيات تفوق بكثير سلبيات. لها المحمولة عبر محركات قاعدة بيانات متعددة - سواء كنت تستخدم ميسكل أو أوراكل أو مجرد عن أي شيء دموي - فقط عن طريق تغيير سلسلة الاتصال، فقد كل الميزات الفاخرة التي نريد استخدامها، وأنها لطيفة ونظيفة. أحب نظيفة. الآن، يتيح إلقاء نظرة على هذا الرمز مرة أخرى، هذه المرة مكتوبة باستخدام كائن بدو: الاختلافات الرئيسية هي أنه لا توجد وظائف أكثر ميسكل. كل ذلك يتم عن طريق كائن بدو، وثانيا، فإنه يستخدم بيان أعدت. الآن، ماذا يكون بيان مسبق تسأله وسيلة لقول قاعدة البيانات قبل تشغيل الاستعلام، ما الاستعلام هو أننا ذاهبون لتشغيل. في هذه الحالة، نقول قاعدة البيانات: مرحبا، أنا ذاهب لتشغيل بيان حدد يريد معرف، أوسيريد وتمرير من مستخدمي الجدول حيث أوسيريد متغير وتمرير هو أيضا متغير .. ثم، في بيان التنفيذ ، ونحن تمرير قاعدة بيانات مصفوفة مع جميع المتغيرات التي تتوقعها الآن. النتائج رائعة. دعونا نحاول تلك أسماء المستخدم وكلمات المرور من قبل مرة أخرى: لم يتم التحقق من المستخدم. رائع. Oh, I just got a little excited, it worked: The check passed. We have a verified admin Now, lets try the data that a clever chap would enter to try to get past our little verification system: This time, we get the following: This is why you are being yelled at when posting questions - its because people can see that your code can be bypassed wihout even trying. Please, do use this question and answer to improve your code, to make it more secure and to use functions that are current. Lastly, this isnt to say that this is PERFECT code. There are many more things that you could do to improve it, use hashed passwords for example, ensure that when you store sensetive information in the database, you dont store it in plain text, have multiple levels of verification - but really, if you just change your old injection prone code to this, you will be WELL along the way to writing good code - and the fact that you have gotten this far and are still reading gives me a sense of hope that you will not only implement this type of code when writing your websites and applications, but that you might go out and research those other things I just mentioned - and more. Write the best code you can, not the most basic code that barely functions. answered Sep 18 13 at 12:28 Because (amongst other reasons) its much harder to ensure the input data is sanitized. If you use parametrized queries, as one does with PDO or mysqli you can entirely avoid the risk. As an example, some-one could use enhzflep) drop table users as a user name. The old functions will allow executing of multiple statements per query, so something like that nasty bugger can delete a whole table. If one were to use PDO of mysqli, the user-name would end-up being enhzflep) drop table users The old functions will allow executing of multiple statements per query - no, they won39t. That kind of injection is not possible with extmysql - the only way this kind of injection is possible with PHP and MySQL is when using MySQLi and the mysqlimultiquery() function. The kind injection that is possible with extmysql and unescaped strings is things like 39 OR 39139 391 to extract data from the database that was not meant to be accessible. In certain situations it is possible to inject sub queries, however it is still not possible to modify the database in this way. ndash DaveRandom Dec 30 12 at 20:58 The MySQL extension is the oldest of the three and was the original way that developers used to communicate with MySQL. This extension is now being deprecated in favor of the other two alternatives because of improvements made in newer releases of both PHP and MySQL. MySQLi is the improved extension for working with MySQL databases. It takes advantage of features that are available in newer versions of the MySQL server, exposes both a function-oriented and an object-oriented interface to the developer and a does few other nifty things. PDO offers an API that consolidates most of the functionality that was previously spread across the major database access extensions, i. e. MySQL, PostgreSQL, SQLite, MSSQL, etc. The interface exposes high-level objects for the programmer to work with database connections, queries and result sets, and low-level drivers perform communication and resource handling with the database server. A lot of discussion and work is going into PDO and its considered the appropriate method of working with databases in modern, professional code. answered Sep 2 15 at 7:20 I find the above answers really lengthy, so to summarize: The mysqli extension has a number of benefits, the key enhancements over the mysql extension being: Object-oriented interface Support for Prepared Statements Support for Multiple Statements Support for Transactions Enhanced debugging capabilities Embedded server support As explained in the above answeres, the alternatives of mysql are mysqli and pdo. API supports server-side Prepared Statements. Supported by MYSQLi and PDO API supports client-side Prepared Statements. Supported only by PDO API supports Stored Procedures. Both MySQLi and PDO API supports Multiple Statements and all MySQL 4.1 functionality - Supported by MySQLi and mostly also by PDO Both MySQLi and PDO where introduced in PHP5.0, whereas MySQL was introduced prior to PHP3.0. A point to note is MySQL is included in PHP5.x though deprecated in later versions. A full-text index in MySQL is an index of type FULLTEXT. Full-text indexes can be used only with InnoDB or MyISAM tables, and can be created only for CHAR. VARCHAR. or TEXT columns. As of MySQL 5.7.6, MySQL provides a built-in full-text ngram parser that supports Chinese, Japanese, and Korean (CJK), and an installable MeCab full-text parser plugin for Japanese. Parsing differences are outlined in Section 13.9.8, ngram Full-Text Parser. and Section 13.9.9, MeCab Full-Text Parser Plugin. A FULLTEXT index definition can be given in the CREATE TABLE statement when a table is created, or added later using ALTER TABLE or CREATE INDEX. For large data sets, it is much faster to load your data into a table that has no FULLTEXT index and then create the index after that, than to load data into a table that has an existing FULLTEXT index. Full-text searching is performed using MATCH(). AGAINST syntax. MATCH() takes a comma-separated list that names the columns to be searched. AGAINST takes a string to search for, and an optional modifier that indicates what type of search to perform. The search string must be a string value that is constant during query evaluation. This rules out, for example, a table column because that can differ for each row. There are three types of full-text searches: A natural language search interprets the search string as a phrase in natural human language (a phrase in free text). There are no special operators. The stopword list applies. For more information about stopword lists, see Section 13.9.4, Full-Text Stopwords. Full-text searches are natural language searches if the IN NATURAL LANGUAGE MODE modifier is given or if no modifier is given. For more information, see Section 13.9.1, Natural Language Full-Text Searches. A boolean search interprets the search string using the rules of a special query language. The string contains the words to search for. It can also contain operators that specify requirements such that a word must be present or absent in matching rows, or that it should be weighted higher or lower than usual. Certain common words (stopwords) are omitted from the search index and do not match if present in the search string. The IN BOOLEAN MODE modifier specifies a boolean search. For more information, see Section 13.9.2, Boolean Full-Text Searches. A query expansion search is a modification of a natural language search. The search string is used to perform a natural language search. Then words from the most relevant rows returned by the search are added to the search string and the search is done again. The query returns the rows from the second search. The IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION or WITH QUERY EXPANSION modifier specifies a query expansion search. For more information, see Section 13.9.3, Full-Text Searches with Query Expansion. For information about FULLTEXT query performance, see Section 9.3.4, Column Indexes. For more information about InnoDB FULLTEXT indexes, see Section 15.8.10, InnoDB FULLTEXT Indexes. The myisamftdump utility dumps the contents of a MyISAM full-text index. This may be helpful for debugging full-text queries. See Section 5.6.2, myisamftdump Display Full-Text Index information. Posted by Dyfed Lloyd Evans on October 21, 2002 Hyphen 039-039 characters break literals at the moment. A search for something like quotGATA-D22S690quot finds all entries containing GATA and not the full hyphenated text. The 039-039 character is treated as a word stop even within literals. The same is true if any of the special text search modifiers are used (eg found with full text searches. Posted by Patrick O039Lone on December 9, 2002 It should be noted in the documentation that IN BOOLEAN MODE will almost always return a relevance of 1.0. In order to get a relevance that is meaningful, you039ll need to: ltBRgtltBRgt SELECT MATCH(039Content039) AGAINST (039keyword1 keyword2039) as Relevance FROM table WHERE MATCH (039Content039) AGAINST(039keyword1 keyword2039 IN BOOLEAN MODE) HAVING Relevance gt 0.2 ORDER BY Relevance DESC ltBRgtltBRgt Notice that you are doing a regular relevance query to obtain relevance factors combined with a WHERE clause that uses BOOLEAN MODE. The BOOLEAN MODE gives you the subset that fulfills the requirements of the BOOLEAN search, the relevance query fulfills the relevance factor, and the HAVING clause (in this case) ensures that the document is relevant to the search (i. e. documents that score less than 0.2 are considered irrelevant). This also allows you to order by relevance. ltBRgtltBRgt This may or may not be a bug in the way that IN BOOLEAN MODE operates, although the comments I039ve read on the mailing list suggest that IN BOOLEAN MODE039s relevance ranking is not very complicated, thus lending itself poorly for actually providing relevant documents. BTW - I didn039t notice a performance loss for doing this, since it appears MySQL only performs the FULLTEXT search once, even though the two MATCH clauses are different. Use EXPLAIN to prove this. Posted by Nathan Ostgard on April 14, 2003 An easy solution to correct for spelling errors for small search items like the name of the city is to build a column that contains the SOUNDEX of each. I039ve found that using a 4 character SOUNDEX works the best. An example: ALTER TABLE cities ADD citysoundex VARCHAR(4) NOT NULL UPDATE cities SET citysoundexLEFT(SOUNDEX(cityname),4) And then to query against: SELECT FROM citites WHERE citysoundexLEFT(SOUNDEX(039Some City Name039),4) Posted by Jim Nguyen on June 18, 2003 The full-text search is slow when there are a lot of rows in the table. I have more than 2 million rows with text and multiple word searches (3 or more) take about 30 seconds to a minute or longer. I am running a Athlon 2.2 Ghz with 512 MB DDR RAM 400 Mhz. Hard drive has seek time of 9 ms. Posted by Alan Riley on July 14, 2003 We too have a database with close to 6 million rows in it. We would like to use the fulltext search, but it is painfully slow. The sad thing is that any one query we need to run only needs to be run on a subset of the rows (think of those 6 million rows as being divided between about 80 different categories, with results only needed to be returned from within a category). It is a shame that there isn039t some way for us to have a fulltext index within the rows of another column which is also indexed. Our next shot at this is going to be to create 80 different tables, one for each category (yuck), just to try to get decent performance on the within-category fulltext search. I would think there is enough interest in fulltext search for there to be an email list dedicated to it where those of us who need to use it on real-world web sites could interact with the developers to try to tune it for the good of the community at large. Posted by Donal McMullan on September 24, 2003 The nature of fulltext indexing is such that the more 039words039 (of greater than the minimum length) that appear in the columns you index, the greater will be size of the index, and the time it takes to create and search that index. 4 Million rows x 6 words per row 24 Million entries 4 Million rows x 30 words per row 120 Million entries If you index intelligently, you may well find that the feature meets your needs, despite what some users may have remarked above. quotNumber of rowsquot is useless as a benchmarking statistic on its own. Posted by Erlend Strmsvik on October 23, 2003 I039ve got a webshop running with mysql. We have 1.6 million booktitles in our database, and our fulltext index is from title and 039extra039 title. Maybe around 5-7 words on average per record. Any fulltext search in our database takes around 1-5ms. A three word search can take a few seconds but still faster than anything else. Even Amazon. This is from our main server which has several thousand hits every day. We are one of the biggest booksellers in my country. - This was in 039reply039 to someone posting earlier about poor performance in 039real world situation039. Posted by Jerome C on December 3, 2003 We have a vast database of products (totaling 3 million rows). The rebuild of the full-text index took 21 minutes to complete. As for the search, a multiple word search on the full-text index of 1 field is as follows: 20 rows returned Query took 1.0263 sec The size of the index is very big though. Index 449,529 KB We are going to eliminate unnecessary words which should make the index smaller. Posted by Ben Margolin on December 19, 2003 The indexing process definitely depends on your machine config. I indexed the same dataset, same mysql version (4.0.16, - standard on Linux, - nt on XP). First machine: a 512M Athlon 2100 running WinXP on a RAID1 array, and it took 9 mins 20 sec. Second machine: 1G RAM P4-2.0ghz, running Linux 7.3 (2.4.20-13.7 kernel), one-spindle (but fast) IDE disk, and it took 29 mins 11 sec. The query was quotalter table msgbodies add fulltext ftibodies (subject, body)quot, and the dataset is about 550M, 1.3 million rows. Both machines were mostly idle when the indexing occurred. I know it039s just anecdotal, but if you run a big alter as I did, don039t be surprised if it takes a while. oh yeah, and then be prepared for MUCH longer than normal insert times when you add large data to the FT indexed columns. This makes sense of course, but, at least on my dataset and hardware, is positively NOT neglible. لمعلوماتك. Posted by Jeffrey Yuen on February 2, 2004 Full text searching in 4.1.1 For Chinese charset in UTF-8 encoding. It needed to set ftminwordlen 1 Posted by Eric Jacolin on February 4, 2004 (MySQL 4.1) To make FULLTEXT MATCH work with Japanese UTF-8 text, be careful that words from your Japanese text be separated by the ASCII space character, not Japanese UTF-8 (or other) spacing characters. (when using phpMyAdmin to manage data write a SQL query, you must switch away from your Japanese IME to insert a space char. ) Posted by Tom Cunningham on February 5, 2004 Tom039s fulltext tips: To get MySQL searching well for me I did: 1. Have a normalized versions of the important columns: where you039ve stripped punctuation and converted numerals to words (0391039 to 039one039). Likewise normalise the search string. 2. Have a combined fulltext index on your searchable columns to use in your 039WHERE039 clause, but then have separate fulltext indexes on each column to use in the 039ORDER BY039 clause, so they can have different weights. 3. For the scoring algorithm, include the independent importance of that record, and include a match of the inclusive index against stemmed versions of the search words (as: quotweddingquot gt quotwedquot, quotweddingsquot). 4. If there039s exactly one result, go straight to that record. 5. If you get no results, try matching against the start of the most important column (WHERE column LIKE 039term039), and put a 5-character index on that column. This helps if someone is searching on a very short word or a stopword. 6. Reduce minimum word length to 3, and make a new stopwords list just using quota an and the is in which we you to on this by of withquot. Use quotREPAIR TABLE xxx QUICKquot to rebuild the index and make a note of the index-file (xxx. MYI) size before and after you make changes. Then use ftdump to tune. Posted by Attila Nagy on April 19, 2004 More about performance: Fulltext search in MySQL isn039t slow really. It039s slower than normal index selects, but that039s not noticable. I039m playing tables that each contains ca 4million records, about 6GB of text that needs to be indexed. The problem lies in the optimization of the queries, that use the MATCH() and AGAINST() functions. So far as I found out MySQL can use in a query only one index. The optimizer looks for the index that will possibly give the smallest amount of rows, then goes trough all of these, and removes those records, that fall out because of the other WHERE statements. When you enter a fulltext search, the server has to use that index. Any other statments could be applied only to the rows that were returned by the search. If you have lots of records, most of the searches will return lots of results. The rest of your query will be executed like if you were executing it against a table that contains the results, and no indexes - obviously that will be processed sequentially. Same thing applies when you use the SQLCALCFOUNDROWS, or LIMIT with high offset values: first the server has to load all the results, then the limit could be applied. If you have to use the fulltext, these are some hints how you could get quite good results: - Try to avoid any group, where, order and any statements for what it039s necessary to get all the results. I know, usually this is impossible. - If you need to show the results on a web page, try to find other methods to get the total number of results than using SQLCALCFOUNDROWS. Better if you don039t tell the user at all how many results there are ) - If indexing text that is in other language than english, before doing anything create a stopword file for your language (That could reduce index size about 30) But most important: think a lot, before you decide to use fulltext search Posted by Peter Dunham on April 22, 2004 We are doing fulltext searches of around 200 tables of 14 -12 million rows each. Upgrading a twin cpu 2Ghz linux machine (running ES 3) from 1GB to 3GB RAM and increasing keybuffersize from 384MB to 512MB has seen load averages go from 1.5-2 to around 0.5, with same usage. Posted by Peter Grigor on May 29, 2004 I039m not sure I agree with your comment that Mysql always uses a fulltext index if you include match. against. I tried a sample query where I used match. against and another value in the where clause (on the primary keyed field) and Mysql039s optimizer picked the primary key index. The statement looked like quotselect something from sometable where match(col1, col2) against (039some text here039) and pkcol 44 Posted by JT Johnston on July 1, 2004 dev. mysqldocmysqlenFulltextBoolean. html states you cannot do a full-text search in Boolean Mode by relevancy. You can, but you need mysql version 4. Take note of quotORDER BY relevancy DESCquot. Here is my codeexample: SELECT, MATCH (YR, AU, ST, SD, SC, BT, BD, BC, AT, AD, AC, JR, KW, AUS, GEO, AN, RB, CO, RR) AGAINST (039Margaret Atwood039 IN BOOLEAN MODE) AS relevancy FROM cclmain WHERE MATCH (YR, AU, ST, SD, SC, BT, BD, BC, AT, AD, AC, JR, KW, AUS, GEO, AN, RB, CO, RR) AGAINST (039Margaret Atwood039 IN BOOLEAN MODE) ORDER BY relevancy DESC Posted by James Day on August 19, 2004 See The Full-Text Stuff That We Didn039t Put In The Manual at dev. mysqltech-resourcesarticlesfull-text-revealed. html for more information about full-text search. Posted by James R on August 31, 2004 Thought some benchmarks for a very large data set might be useful to people. I created a full-text index on a 100 gig database, where the index was on a column where the data totals 3 gig. The index added 2 gig to the database. The database has 2,741,000 records. The textual content is technical literature in US English. Machine: The machine is an Athlon XP 3200 w 1 gig RAM, one drive for the OS, and another 250GB EIDE drive for the MySQL data. OS is Redhat 9. Index creation: 3 hours 5 min. Most of that time was probably copying the table (since MySQL copies the table before it modifies it). The process was definitely disk-limited -- CPU usage was never regularly above 50. I believe that were it not for the excess data to copy, the index creation would have taken about 45 minutes. Queries were chosen to compare rare words, common words, and words of different lengths. All queries seemed to be disk-limited (CPU utilization hardly moved off baseline), which makes sense given that there is not enough RAM to hold the index in memory. All queries were done mutiple times and the average time reported. Results follow. Word, Rows, Seconds, SecondsRow ---------------------------------------- bilobed, 4, 0.15, 0.0375 mends, 4, 0.19, 0.0475 nanotechnology, 23, 0.64, 0.0278 bioluminescent, 53, 1.53, 0.0289 photosynthesis, 81, 2.21, 0.0273 graphite, 5070, 123.00, 0.0243 bicycle, 5385, 122.00, 0.0227 titanium, 13503, 350.00, 0.0259 (titanium, graphite), 18423, 425.00, 0.0231 metal, 151095, 4020.00, 0.0266 This is just a small test on the way to indexing the full 100 gig in the database that I am working on for freepatentsonline. I039ll post results for that once I have a new server built. Posted by noel darlow on September 3, 2004 In reply to Patrick O039Lone039s post, above: The first, non-boolean MATCH can039t keep pace with the second, boolean one since it does not recognise the boolean operators. A search for foo might turn up rows with foo, foobar, foofighters, etc but the non-boolean, relevance MATCH can039t quotcountquot anything except foo. Same problem with a phrase search. Since effectively you can039t use boolean operators in the second, boolean MATCH, it039s rendered pointless. Results could be post-processed with your own ranking algorithm but it039s kind of odd that you can039t do a boolean search AND rank results in the query. Posted by Dave M on September 12, 2004 Those looking to simply match a search phrase in a large group of words, try this: SELECT FROM data WHERE haystack LIKE (039needle039) AND haystack RLIKE 039:lt:needle:gt:039 This query will produce the same result as the following query, but is roughly 20X faster. SELECT FROM data WHERE haystack RLIKE 039:lt:needle:gt:039 For more than one word use: haystack LIKE (039word1word2039) AND haystack RLIKE 039:lt:word1:gt:.:lt:word2:gt:039 Posted by James Day on September 26, 2004 The Wikipedia encyclopedia uses MySQL boolean full text search and MySQL 4.0.20. You can assess the speed yourselves. About 350,000 articles rows in the English language version, roughtly 5GB total. For all languages, one million articles and 10GB of text. It039s very important to have a sufficiently large keybuffersize. Get much of the index in RAM and searches are typically very fast. Because we use InnoDB tables and can039t share cache between InnoDB and MyISAM, we039re moving to a setup which will use a dedicated and MyISAM tuned search server. We run a slow query killer which will kill queries once their allowed time expires. That time depends on server load (active thread count). Documented at wp. wikidevQuerybane It turns out that our current search often spends most time on things other than full text search - an improved version which is much more efficient is pending. Remember that you can use a self join to get around the one index per query limit of MySQL. Search remains our most problematic load feature, requiring a couple of quite capable slaves to keep up at busy time. If we039re working on the servers and the remainder can039t handle the load, we switch to Google or Yahoo search. This is from one of the top few hundred sites on the net, so it039s scaling pretty well for our application. One server was sufficiently fast to take us to the top 1,000. Posted by Andrew Panin on October 7, 2004 Hi all I had a problem with FULLTEXT search and after I solved it, I want to try to help you. I thought that FULLTEXT search is slow. That was. But I did a simple trick: 1. For example, we have 4 tables with fulltext index. We need to perform fast search on them. 2. Do the following: CREATE TEMPORARY TABLE xxx SELECT id, name, MATCH(name) AGAINST (039searchstring039) AS relevancy FROM table1 INSERT INTO xxx SELECT id, name, MATCH(name) AGAINST (039searchstring039) AS relevancy FROM table2. 3. Then, when the temporary table is filled with the data, do the simple select from it: SELECT id, name FROM xxx ORDER BY relevancy DESC I think, it is the optimal way to make a VERY FAST fulltext search from a number of tables. I hope, this will be helpful. Posted by Dennis van den Ende on December 27, 2004 Allthough my fulltext serach works fine, i still have problems with it. i compare products with there prices. i used the quotrelevancequot idea (written above). But it will not recognize it correctly. Heres my query: SELECT , MATCH( field ) AGAINST (039blabla039) as relevance FROM table WHERE MATCH( field ) AGAINST (039blabla039 IN BOOLEAN MODE ) HAVING relevance gt 0.2 for example it finds 18 rows. to increase the rows, i checked (manuelly) the relevance. 3 above 18 (all 18.xxx) and the rest about 10.3 or lower. If i increase the quothavingquot to 15, it finds only 2 of 3. The field i use is the only index-field and ofcourse a fulltext specific field. it seems that the relevance is taking part of the search results. i am still looking for another idea but the relevance would cover my needs 100 update I just updated the mysql version from 4.0.15 to 4.1.8 and it works perfectly. Posted by Mauricio Wolff on February 4, 2005 to set up minlen and stopwordfile in windows (win2k or xp): 1. run services. msc to check what. ini your mysql is reading (in my case, quotC:MySQLbinmysqld-ntquot --defaults-filequotC:MySQLmy. iniquot MySQL) 2. change your my. ini like this: mysqld ftminwordlen3 ftstopwordfilequotC:MySQLstop. txtquot 3. restart your mysqld at services. msc 4. reindex your table using REPAIR TABLE tblname QUICK Posted by Peter Laursen on April 28, 2005 it is legal to use two different arguments with the quotdouble match constructionquot, i. e. select . match (artist, album, title) against (039blues in orbit039) from musicfiles where match (artist, album, title) against (039ellington039) will FIND all records with 039ellington039 as substring of artist, album or title, but will RATE them as the search match039es 039blues in orbit039 You can even. ORDER BY or GROUP BY MATCH (kunstner, albumtitel, titel) AGAINST (039prelude to a kiss039). or against anything else Posted by Grant Harrison on June 9, 2005 Maybe a little off topic here. Alternatively, instead of doing all full-text search within MySql database, you can pull data out and create an index on it. It039s a much faster search. I am using DBSight to search on 1.7million records of 1.2G data, on a P3 450MHz, 256MRam, with sub-second performance. Taking search out of database also give you capability to customize stemmer and query parser. Posted by Erik Petersen on July 13, 2005 When using FULLTEXT queries on large set data sets it039s critical to LIMIT your results. Doing some experimentation has made this very clear. Using a data set of 5.5 million rows of forum message posts indexed with a single FULLTEXT index: select id, match(post) against(039foo039) as score from messages where match (body) against( 039foo039 ) . 155323 rows in set (16 min 7.51 sec) select id, match(post) against(039foo039) as score from messages where match (body) against( 039foo039 ) limit 100 . 100 rows in set (1.25 sec) I ran a number of other tests on various terms known to be in the text with similar results. These were run in reverse order shown. Make sure you return only the rows you need or you will suffer. For a search engine application returning pages of results keep in mind that nobody is going to ever see page 74 Cap the results to a reasonable maximum trading response time for completeness where possible. Posted by kim markegard on August 25, 2005 In regards to Dyfed Lloyd Evans comment, I believe that quot. quot will also cause this which is unfortunate because we have product name acronyms we039d like to seach. Posted by Nathan Huebner on October 29, 2005 After tons of hours today working on this, I HAVE FINALLY MASTERED THE TECHNIQUE OF USING THIS THING. This query is what you send to your MySQL to return the results. I put the LIMIT so that you don039t overflow. queryretquotSELECT ProductID, Title, Description, Price, RetailPrice, MATCH (Title) AGAINST (039keyword039) AS score FROM server. book HAVING score gt 0 LIMIT start, maxretquot This query will COUNT the number of rows it found. (I believe that039s correct), I don039t believe it counts occurrences, just rows. I saw that if you pull back without a LIMIT above, and count that way, it039s 100000x slower. So do your count like this: querycountquotSELECT count(MATCH(Title) AGAINST(039keyword039)) AS score FROM server. book WHERE MATCH (Title) AGAINST (039keyword039) HAVING score gt 0quot Make sure you have your Primary Key setup, your Title and Description as SEPARATE FULLTEXT INDEXES. I spent a few hours boggling over this. Posted by Saqib Aziz on November 24, 2005 There is no way to perdict what maximum relevance rank could be. While working with full text searches one may want to show percentages as the criteria for indicating how close a particular record was to the search query. To achieve this, one way is to select the maximum relevance rank or score and then use it( as a denominator ) with every single record score to get percentage equivalent of score. For the sake of example, consider we have 6 as maximum rank and 2,3,4.234 are scores for three different records. Now to get percentage we have to do simple maths i. e. we can divide each score by 6(max rank) and then mulitply the result with 100. Hope this helps someone. Posted by Nathan Huebner on January 12, 2006 Tips on how to maximize performance, and minimize return time. Let me guess: you have a lot of data, and you went ahead and FULLTEXT indexed a column within that large pile of data. To put it in simple words: not cool. How long does your data take to return from a FULLTEXT search. 5 seconds More If you039re returning data under 3 seconds, then you039re ok, but if you want it to return in 1.3 seconds, here039s what I did. 1. Dont fulltext index a column within a huge table. Instead, take a Unique Identifier, and the text you039re searching, and copy it to another table. Use this to export your columns: SELECT uniquecolumn, mytextsearchcolumn FROM mydatabase. mytable INTO OUTFILE quotc:pathoutfile. txtquot That will export your data to a file in Tab Delimited format. Now, create a new table somewhere, and call it fulltextengine or something, with only 2 columns (less is better), you could add one more if you need to. Now import your data: LOAD DATA INFILE quotc:pathoutfile. txtquot IGNORE INTO TABLE mydatabase. fulltextengine Now, create your FULLTEXT index on your search field. عظيم. Now you have a separate table for searching. So if you want to try it out, go into MySQL, and try this, or PHPmyAdmin: SELECT SQLCALCFOUNDROWS uniquecolumn, searchcolumn, MATCH (searchcolumn) AGAINST (039Keyword Goes Here039) AS score FROM mydatabase. fulltextengine HAVING score gt 0 Hope this helps It may add extra maintenance, but I will give up my soul to increase search speeds by 6x. Posted by Joe Soap on July 11, 2006 Not sure if this is useful for people trying to reduce their search dataset. But what I039m doing is preprocessing the text before I add it to the database. So I add the full text to my FileData column, but I also preprocess the text and put this processed text into a Keywords column. Then I search only the keywords column and never the full text. This technique obviously (you039ll see why) doesn039t work for phrase matching but it may speed up the search time by reducing the size of the dataset to search. Here039s the algorithm I use. 1. extract the text 2. count each word of 2 or more characters in the text and record the frequency that each occurs 3. from this list of words 2 or more characters long, remove the k (k currently 500) most common words in the english dictionary 4. sort the list so that the most frequently occurring words appear first 5. take the first n words as the final keywords, where n gt 0 and n lt the total number of remaining words Posted by Tasuku SUENAGA on July 30, 2006 If you have performance problems on fulltext search, Please try Senna, fulltext search engine that can be embedded in MySQL. qwik. jpsenna Original MySQL fulltext search is slow for query SELECT COUNT() or SELECT FROM xx LIMIT largenumber, x. These queries are very fast with Senna039s 2ind patch. Posted by Gary Osborne on August 19, 2006 I039m not convinced that stop-words are of great value. Sure, they might reduce the size of the index and speed-up queries for some kinds of databases. But there are two fundamental flaws with quotmandatoryquot stop-words. Firstly, without knowing in advance the nature of the data, how can any programmer proclaim to know which words should be excluded because they have no value Secondly, if a user includes any stop word in a search query, then by definition that word039s value can not be zero. If the word039s value was zero, then why would the user use it in a search query If you need to disable stop-words without re-compiling, consider appending a character to the end of each word in your text before inserting your text into the database. I used quotqquot. I also right-padded all words shorter than 4 characters to a length of 4 characters by appending quotqquots. And I appended a quot quot to the end of my text string before inserting into the database. After retrieving my text from the database, I did a global replace on my text. I changed quotqqqquot to quotquot, quotqqquot to quotquot, and quotq quot to quot quot - in that order - to restore the text to it039s original form. That was not the best solution but it worked. Luckily for me, my text was simply a space delimited list of words without and punctuation. Otherwise, my quotqquot encoding and decoding would have been more difficult. Posted by Sebastian Alberoni on September 27, 2006 Combining MATCH with MAX, GROUP BY and ORDER BY can be of a lot of help when retrieving results in the correct order regarding relevance. For example, using this I could solve a problem with one table called 039Professional039, which had a many-to-many reference to another table 039Profession039. Although I was using DISTINCT I was getting duplicate results because of different relevance values that MATCH was giving to the different entrances in 039Professions039. Here I am copying the final query that worked OK (it039s a bit simplified): select distinct p. idProfessional, MAX(MATCH (pssion. name, pssion. description) AGAINST (039string to search039)) as professionRanking FROM professional p, professionalprofession pp, profession pssion WHERE pp. ProfessionalidProfessional p. idProfessional AND pp. ProfessionidProfession pssion. idProfession and ( MATCH (pssion. name, pssion. description) AGAINST (039string to search039) GROUP BY p. idProfessional ORDER BY professionRanking DESC Posted by Miguel Velilla meucat on May 20, 2007 The truth behind fulltext search, is that MySql first split text into single words, then indexes isolated words pointing to records. These are logical steps that many of us previously had tried before MySql fulltext commands creation. I created a PHP program some years ago to perform exactly the same split-and-index task. This is the reason MATCH command allows prefixed wildcards but not postfixed wilcards. Since single words are i ndexed, a postfix wildcard is impossible to manage in the usual way index does. You can039t retrieve 039nited states039 instantly from index because left characters are the most important part of index. Even so, I hope MySql developers some day implement postfix wildcars, because for many of us, it is important to perform a truly 039full text039 search. To say something, if I have a record with the word 039database039. I want retrieve this record when searching by 039tabas039, an impossible task for actual fulltext search command. It039s easy to see that such a command can gain lot of performance, even when MySql developers be obliged to search byte to byte into the indexed words. If you have a big table with text descriptions. to say 1 GB size, it is possible that quantity of different words into text will not pass from 500.000, maybe 1.000.000 words, averaging 8 bytes each, total 8 MB of data to be browsed, instead the 1 GB you should seek byte to byte to find what you want. This is a 1 GB 8 MB 125. or two orders of magnitude lower in terms of processing. Posted by Sergejzr Zr on July 27, 2007 Unfortunately it is not possible to combine Fulltext field and normal (i. e integer) field into one index. Since only one index per query can be used, that seems be a problem Table: id(integer primary key)content(text fulltext indexed)status(integer key) Note that executing folowing query, mysql will use only one index. Either fulltext, or status (Depending on intern statistics). Q1: SELECT FROM table WHERE MATCH(content) AGAINST(039searchQuery039) AND status 1 However it is still possible to use both indexes in one query. You will need a new index on id, status pair and use join. Thus mysql will be able to use one index for each table. Q2: SELECT t1. from table t1 LEFT JOIN table t2 ON(t1.idt2.id) WHERE MATCH(t1.content)AGAINST(039searchQuery039) AND status1 Q2 will run significantly faster than Q1 at least in my case :) Note the overhead: You will need an id for each row and a key wich is spanned over needed fields strating with id. Posted by Phoebe Bright on August 14, 2007 Using this for the first time I picked an unfortunate test and took a while before I worked out why it wasn039t working. In the hopes of saving other newbies some time: This will work: SELECT FROM myfile WHERE description LIKE 039sea039 But this will return nothing: SELECT FROM myfile WHERE MATCH (description) AGAINST (039sea039) BECAUSE THE DEFAULT MIN LENGTH IS 4 need to set ftminwordlen to 3 in the configuration file if you want it to work. Posted by Mohamed Mahir on September 28, 2007 To get the first exact matching record of the Full text search i wrote like this.. SELECT MATCH (column) AGAINST (039keyword039) relevancy FROM t1 WHERE MATCH (column) AGAINST (039keyword039) ORDER BY relevancy DESC LIMIT 1 Posted by Neil Delargy on October 19, 2007 One solution to find a word with a dashes or hyphens in is to use FULL TEXT SEARCH IN BOOLEAN MODE, and to enclose the word with the hyphen dash in double quotes. Posted by Derek Foreman on October 31, 2007 I use Mediawiki that makes use of the FullText searching and was not getting results I knew were in the database. After reading this page I realized that mysql won039t index words 3 characters or less by default. The solution is detailed clearly in this page Change the ftminwordlen setting. You can find what the server is using by running: SHOW VARIABLES LIKE 039ft039 Then you039ll have to rebuild the indexes on the tables that have FULLTEXT indices, because the server I039m using had several databases I needed a quick way to identify which tables these were. SELECT DISTINCT TABLESCHEMA, TABLENAME FROM COLUMNS WERE COLUMNKEY 039MUL039 I could then rebuild the tables. Posted by Jane Doe on November 28, 2007 Very fast and flexible, and works nice with MySQL. Eliminates many of the issues mentioned here in the comments, also ) MATCHAGAINST didn039t work how I intended. Here039s how I finally solved what I thought MATCHAGAINST should have been doing from the beginning: Posted by Carlos Dias on August 8, 2011 Basically this approach makes me think twice because of the next logical steps: 1- If your working in one table with a lot of records. each time the records are updated or new lines inserted the index must be (obviously)recreated. if it039s myisam. writing operations the table is locked. 2- I guess that the best approach towards this it039s probably the logic of: when tables are huge. not creating indexes for text search. create cachesql. (cachesql is one index). Somehow anticipating these problems. like i write are not problems to ignore. Why this is the best option. because if people use one file to log the last writing operations and compare it with the file that contains the results cache(best approach. cronjob). it039s only necessary to point to the file that contains the resultscache. The logic of:If there are 500 000 000 of conjugations of wordsphrases, etc what039s the need of indexing everything if only 50 000 conjugations are usedseeked, etc. Posted by Bradley Smith on February 21, 2012 Alan, instead of creating 80 different tables, one for each category, why not partition the table by the category so the records with that category would be grouped together within the partition and then your only searching within the specific category and more direct and faster route to the data you want to search Posted by Nasser W on September 2, 2013 MySQL fulltext search works well for Arabic. Just make sure of the following where needed: 1. COLLATION utf8unicodeci amp CHARACTER SET utf8. (Databases, Tables, and Columns). 2. Index words of 3 letters and more. This is Very Important for Arabic, ftminwordlen 3 (see show variables like quotftquot) 3. Check the version of MySQL (5.5 or 5.6), and Engine (InnoDb or MyIsam) Sign Up Login You must be logged in to post a comment.

No comments:

Post a Comment