مرحبا كيفن انا مبرمج ويب واندرويد من سنه تقريبا
سوري مقيم في امريكا تحديدا نيوروك :))) عمري 11 سنه
اليوم برمجة كلاس للأتصال بقاعدة البيانات بأستخدام الـ Mysqli
line 1 of code
<?php
if (preg_match('/' . basename(__FILE__) . '/', $_SERVER['PHP_SELF']))
die(header("HTTP/1.1 404 Not Found"));
////////////////////////////////////////////////////////////////////////
// start class class connectbyMysqli { # private static variable (charset) with value UTF-8 private static $charset = 'utf-8';
#Off \ On .. Errors show in file
private static $Error_settings = 'Off';
#variable connecting
public $mysqli;
////////////////////////////////////////////////////
# Get variables private from config file
////////////////////////////////////////////////////
private $server_URL;
private $server_USR;
private $server_PASS;
private $server_DB;
////////////////////////////////////////////////////
# Get variables Config
//////////////////////////////////////////////////////////////////
public function __construct($localhost,$user_host,$user_pass,$DB)
{
# display Errors ..
ini_set("display_errors",self::$Error_settings);
###################################################
# variables config ...
###################################################
$this->server_URL = $localhost;
$this->server_USR = $user_host;
$this->server_PASS = $user_pass;
$this->server_DB = $DB;
###################################################
// result connecting
$this->mysqli_connect();
}
//////////////////////////////////////////////////////////////////
public function mysqli_connect ()
{
$this->mysqli = new mysqli($this->server_URL,$this->server_USR,$this->server_PASS,$this->server_DB);
if ($this->mysqli->connect_error)
{
die('
<title>خطأ ..</title>
<link rel="stylesheet" href="style_error.css" />
<div dir="rtl" id="content">
<table dir="rtl">
<tr>
<th colspan="2">لا يمكن الاتصال بقاعدة البيانات</th>
</tr>
<tr>
<td class="bold">رقم الخطأ :</td>
<td>' . $this->mysqli->connect_errno . '</td>
</tr>
<tr>
<td class="bold">تفاصيل الخطأ :</td>
<td style="direction: ltr;" >' . $this->mysqli->connect_error . '</td>
</tr>
<tr>
<td class="bold">الحلول المقترحه :</td>
<td style="font-family: tahoma;">
قم بفحص بيانات ملف الاتصال بالقاعده جيداً
</td>
</tr>
</table>
</div>
');
}
$this->mysqli->query("SET NAMES ' " . self::$Error_settings . " '");
return $this->mysqli;
}
# Close connecting
public function __destruct()
{
$this->mysqli->close();
}
////////////////////////////////////////
} ?> وهذا الكونفج line 2 of code
if (preg_match('/' . basename(__FILE__) . '/', $_SERVER['PHP_SELF'])) die(header("HTTP/1.1 404 Not Found"));
//////////////////////////////////////////////////////////////////////////
Config class Settings Include
include "Class.connect.mysqli.php";
confing Settings
/////////////////////////////////////////////////////////////////////
define('SERVER_NAME','localhost'); // localhost
define('USER_NAME','root'); // user databse
define('USER_PASS','102030'); // password user database
define('DATABASE','test'); // database name
/////////////////////////////////////////////////////////////////////
Don't change anything after this line >>
$mysqli = new connectbyMysqli(SERVER_NAME,USER_NAME,USER_PASS,DATABASE);
$db = $mysqli->mysqli;
?>
عند عمل كلاس تظهر صفحه بيضاء .. للعلم انا اعمل على سيرفر محلي
التعليقات