توجد طريقتين لفعل ذلك، فإما أن تكتب ذلك بنفسك وهذه هي طريقة مختصرة لفعل ذلك:
أولا تأكد من إصدارات البرامج، وهذه هي طريقة التأكد من اصدار php:
$php_version=phpversion();
if($php_version<5)
{
$error=true;
$php_error="PHP version is $php_version - too old!";
}
بعد ذلك تأكد من عدم وجود أخطاء في الاتصال قواعد البيانات( معلومات الاتصال حصلنا عليها من المستخدم):
$db_error=false;
// try to connect to the DB, if not display error
if(!@mysql_connect($_POST['dbhost'],$_POST['dbuser'],$_POST['dbpass']))
{
$db_error=true;
$error_msg="Sorry, these details are not correct.
Here is the exact error: ".mysql_error();
}
if(!$db_error and !@mysql_select_db($_POST['dbname']))
{
$db_error=true;
$error_msg="The host, username and password are correct.
But something is wrong with the given database.
Here is the MySQL error: ".mysql_error();
}
البيانات التي ستحصل عليها من المستخدمين لقواعد البيانات ستكون مشابهة لهذه:
// try to create the config file and let the user continue
$connect_code="<?php
define('DBSERVER','".$_POST['dbhost']."');
define('DBNAME','".$_POST['dbname']."');
define('DBUSER','".$_POST['dbuser']."');
define('DBPASS','".$_POST['dbpass']."');
?>";
إذا استطعت كتابة هذه المعلومات إلى ملف الإعداد فإفعل ذلك، وإلا اجعل المستخدم يفعل ذلك:
if(!is_writable("inc/db_connect.php"))
{
$error_msg="<p>Sorry, I can't write to <b>inc/db_connect.php</b>.
You will have to edit the file yourself. Here is what you need to insert in that file:<br /><br />
<textarea rows='5' cols='50' onclick='this.select();'>$connect_code</textarea></p>";
}
else
{
$fp = fopen('inc/db_connect.php', 'wb');
fwrite($fp,$connect_code);
fclose($fp);
chmod('inc/db_connect.php', 0666);
}
في النهاية أنشئ الجداول واملئها بالبيانات المطلوبة:
// assuming you have DB established connection
// and have the resource identifier in $db_link
$q="DROP TABLE IF EXISTS `users`;";
mysqli_query($db_link,$q);
$q="CREATE TABLE `users` (
`id` bigint(20) unsigned NOT NULL auto_increment,
`username` varchar(100) NOT NULL default '',
`level` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
mysqli_query($db_link,$q);
$q="INSERT INTO `users` (username, level) VAUES ('admin','admin');";
mysqli_query($db_link,$q);
إذا لم تعجبك هذه الطريقة فيمكنك استخدام احدى سكربتات التثبيت الجاهزة مثل PHPAppInstaller وZZ/OSS Installer وغيرها.
المصدر