ظƒظ„ط§ط³ ظ„ظ„ط§طھطµط§ظ„ ط¨ظ‚ط§ط¹ط¯ط© ط§ظ„ط¨ظٹط§ظ†ط§طھ ط¹ظ† ط·ط±ظٹظ‚ ط¨ط±ظ…ط¬ط© ط§ظ„ظƒط§ط¦ظ†ط§طھ



كلاس من تصميمي خاص بالاتصال بقاعدة البيانات
يمكن استخدامه من قبل الاخوة الاعضاء في حالة كان مناسب لهم

هذا الكلاس هو جزء من برمجتي في سكريبت script المقالات BHLsimpleTool سوف اقوم بنشره خلال شهر رمضان الكريم. و هو اسكريبت script متكامل يصلح للمواقع الاخبارية و مواقع المعلومات.

الكلاس اختصرته بما فيه الكفاية حتى يتمكن الاخوة المبتدئين من فهمه. الملف الاصلي مكون من خمسة ملفات ضخمة.

ملحوظة : في حالة استخدام هذا الكلاس في اي سكريبت script - قم بتضمين ملف BHL_BD.php كما يلي :


رمز PHP:
<code style="white-space:nowrap"> <code> require_once('BHL_DB.php');
</code> </code>

ارجو ان أكون قد وفقت فيه

Settings.php

رمز PHP:
<code style="white-space:nowrap"> <code> <?PHP
# ------------------------------------------------------------------------------------------#
# BHLsimpleTool - PHP Content Management System #
# Copyright (c) 2014 bhl.org #
# <http://www.bhl.org/> #
# -----------------------------------------------------------------------------------------#
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
#-------------------------------------------------------------------------------------------#
# This program is distributed in the hope tat it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# -----------------------------------------------------------------------------------------#
// معلومات الاتصال بقاعدة البيانات
$BHL_HOST = "write-your-serverhost-here"; // يجب تعبة السيرفر SERVER الخاص بك
$BHL_USER = "write-your-databaseyuser-here"; // يجب تعبة اسم مستخدم قاعدة البيانات
$BHL_PASS = "write-your-databasepassword-here"; // يجب تعبة كلمة مرور قاعدة البيانات
$BHL_NAME = "bhl"; // قم بكتابة اسم قاعدة البيانات



?>
</code> </code>

BHL_english.php

رمز PHP:
<code style="white-space:nowrap"> <code> <?PHP
# ------------------------------------------------------------------------------------------#
# BHLsimpleTool - PHP Content Management System #
# Copyright (c) 2014 bhl.org #
# <http://www.bhl.org/> #
# -----------------------------------------------------------------------------------------#
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #



#-------------------------------------------------------------------------------------------#
# This program is distributed in the hope tat it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# -----------------------------------------------------------------------------------------#


DEFINE('_INVALIDDBCONN', 'INVALID DATABASE CONNECTION');
DEFINE('_INVALIDDBSEL', 'INVALID DATABASE CONNECTION');
DEFINE('_INVALIDDBQUERY', 'INVALID DATABASE QUERY');
DEFINE('_INVALIDDBQUERYFETCH', 'Sorry, we can not execute your query');
DEFINE('_USERFIRSTNAMEEMPTY', 'Hey, your first name should not be blank.!');
DEFINE('_USERFIRSTNAMEWITHOUTNO', 'Hey, your first name should be without numbers.!');
DEFINE('_USERFIRSTNAMELONG', 'Hey, your first name should not be more than 30 characters.!');
DEFINE('_USERFAMNAMEEMPTYE', 'Hey, your family name should not be blank.!');
DEFINE('_USERFAMNAMEWITHOUTNO', 'Hey, your family name should be without numbers.!');
DEFINE('_USERFAMNAMELONG', 'Hey, your family name should not be more than 30 characters.!');
DEFINE('_USERNAMEEMPTYE', 'Hey, your user name should not be blank.!');
DEFINE('_USERNAMELONG', 'Hey, your user name should not be more than 30 characters.!');
DEFINE('_USERPSWDEMPTYE', 'Hey, your password should not be blank.!');
DEFINE('_USERPSWDMORE', 'Hey, your password should be more than 5 characters.!');
DEFINE('_USERPSWDLONG', 'Hey, your password should not be more than 30 characters.!');
DEFINE('_USERVERPSWDMATCH', 'Hey, your verfied password did not matched.!');
DEFINE('_USERVERPSWDEMPTY', 'Hey, your verfied password should not be blank.!');
DEFINE('_USEREMAILEMPTYE', 'Hey, your Email should not be blank.!');
DEFINE('_USEREMAILRREG', 'Hey, you entered an invalid email address.!');

?>
</code> </code>

BHL_DB.php

رمز PHP:
<code style="white-space:nowrap"> <code> <?PHP
# ------------------------------------------------------------------------------------------#
# BHLsimpleTool - PHP Content Management System #
# Copyright (c) 2014 bhl.org #
# <http://www.bhl.org/> #
# -----------------------------------------------------------------------------------------#
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
#-------------------------------------------------------------------------------------------#
# This program is distributed in the hope tat it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# -----------------------------------------------------------------------------------------#

require_once('Settings.php');
require_once(
'BHL_english.php');

//الرجاء عدم تغيير اي بيانات فيما يلي
class BHL_DB {

private
$BHL_DB_HOST;
private
$BHL_DB_USER;
private
$BHL_DB_PASS;
private
$BHL_DB_NAME;
private
$DB_CONNECTION;
private
$DB_SELECT;
private
$DB_RESULT;

// بناء معلومات قاعدة البيانات

public function __construct($BHL_HOST, $BHL_USER, $BHL_PASS, $BHL_NAME){
$this->BHL_DB_HOST = $BHL_HOST;
$this->BHL_DB_USER = $BHL_USER;
$this->BHL_DB_PASS = $BHL_PASS;
$this->BHL_DB_NAME = $BHL_NAME;
$this->DB_CONN ($this->BHL_DB_HOST, $this->BHL_DB_USER, $this->BHL_DB_PASS, $this->BHL_DB_NAME);
}

// هدم الاتصال بقاعدة البيانات

public function __destruct(){
$this->DB_DISCONNECT();
}

// انهاء الاتصال المؤقت بقاعدة البيانات

public function __sleep(){
$this->DB_DISCONNECT();
return array(
'BHL_DB_HOST', 'BHL_DB_USER', 'BHL_DB_PASS','BHL_DB_NAME');
}

// الرجوع للاتصال بعد الانهاء المؤقت

public function __wakeup(){
try{
if(!
$this->DB_CONNECTION){
throw new
Exception(_INVALIDDBCONN);
}
return
$this->DB_CONNECTION;
}
catch (
Exception $e) {
echo
"Error (File: ".$e->getFile().", line ". $e->getLine()."): ".$e->getMessage();
}
}

public function
DB_CONN($BHL_HOST, $BHL_USER, $BHL_PASS, $BHL_NAME){
$this->DB_CONNECTION = @mysql_connect($BHL_HOST, $BHL_USER, $BHL_PASS);
try{
if(!
$this->DB_CONNECTION){
throw new
Exception(_INVALIDDBCONN);
}
if(!
is_resource($this->DB_CONNECTION)){
throw new
Exception(_INVALIDDBCONN);
}
if(!@
mysql_select_db($BHL_NAME, $this->DB_CONNECTION)){
throw new
Exception(_INVALIDDBSEL);
}
}
catch (
Exception $e) {
echo
"Error (File: ".$e->getFile().", line ". $e->getLine()."): ".$e->getMessage();
}
}

public function
DB_DISCONNECT(){
try{
if(!
$this->DB_CONNECTION){
throw new
Exception(_INVALIDDBCONN);
}
@
mysql_close($this->DB_CONNECTION);
unset(
$this->DB_CONNECTION);
}
catch (
Exception $e) {
echo
"Error (File: ".$e->getFile().", line ". $e->getLine()."): ".$e->getMessage();
}
}

// التحقق من استعلام ما

public function DB_QUERY($QUERY){
try{
if(!
$this->DB_CONNECTION){
throw new
Exception(_INVALIDDBCONN);
}
$this->DB_RESULT = mysql_query($QUERY, $this->DB_CONNECTION);
if (
$this->DB_RESULT != 0) {
return
1;
}
else {
return
0;
}
}
catch (
Exception $e) {
echo
"Error (File: ".$e->getFile().", line ". $e->getLine()."): ".$e->getMessage();
}
}

// استدعاء البيانات

public function ROWFETCHING(){
return
mysql_fetch_array($this->DB_RESULT);
}

// الاستدعاء الكامل لبعض الاستعلامات

public function FETCHALLROW(){
while (
$ROW = mysql_fetch_array($this->DB_RESULT)) {
$FROW&#91;&#93; = $row;
}
mysql_free_result($this->DB_RESULT);
return
$FROW;
}

// التشييك على الصفوف

public function DB_NUMROWS(){
return
mysql_num_rows($this->DB_RESULT);
}

// التأكد من عدم وجود بيانات بقاعدة البيانات

public function DB_FREERESULT(){
mysql_free_result($this->DB_RESULT);
}

// نسخ قاعدة البيانات

public function DBCLONEOBJECT()
{
return new
BHL_DB();
}
}

// استدعاء قاعدة البيانات بكامل اساليبها في الكلاس

$BHLDB_CONN = new BHL_DB($BHL_HOST, $BHL_USER, $BHL_PASS, $BHL_NAME);






?>
</code> </code>










©المشاركات المنشورة تعبر عن وجهة نظر صاحبها فقط، ولا تُعبّر بأي شكل من الأشكال عن وجهة نظر إدارة المنتدى©