ایجاد table در یک دیتابیس
دوستان می خواهیم یک Table با توجه به مشخصات زیر در یک دیتابیس ایجاد کنیم
البته من این رو از یک فایل PHP برداشتم ولی متاسفانه هنگام اجرا Table ها ایجاد نمی شند
به همین دلیل می خوام به صورت دستی این کار رو انجام بدم
لطف کنید من رو در این ضمینه راهنمایی بفرمایید
کد PHP:
mysql_query("CREATE TABLE user (
id tinyint(4) NOT NULL auto_increment,
username text NOT NULL,
password text NOT NULL,
number text NOT NULL,
average text NOT NULL,
paye text NOT NULL,
name text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
البته لازم به ذکر است که کل اسکریپت PHP به صورت زیر هست
برای کسانی که اطلاعات بیشتر می خواهند :)
کد PHP:
<?
// Programmer : FAMIZBAN.Com
include "include/config.php";
// --- \\ Install Databases // --- \\\
mysql_query("CREATE TABLE user (
id tinyint(4) NOT NULL auto_increment,
username text NOT NULL,
password text NOT NULL,
number text NOT NULL,
average text NOT NULL,
paye text NOT NULL,
name text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE maghale (
id tinyint(4) NOT NULL auto_increment,
title text NOT NULL,
catid text NOT NULL,
nevis text NOT NULL,
body text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE nomre (
id tinyint(4) NOT NULL auto_increment,
nomr text NOT NULL,
date text NOT NULL,
dars text NOT NULL,
magh text NOT NULL,
nesh text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE magh (
id tinyint(4) NOT NULL auto_increment,
name text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE cat (
id tinyint(4) NOT NULL auto_increment,
name text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE paye (
id tinyint(4) NOT NULL auto_increment,
name text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE stat (
id tinyint(4) NOT NULL auto_increment,
tvisit text NOT NULL,
yvisit text NOT NULL,
avisit text NOT NULL,
cash text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE matn (
id tinyint(4) NOT NULL auto_increment,
title text NOT NULL,
body text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE azmoon (
id tinyint(4) NOT NULL auto_increment,
name text NOT NULL,
tedad text NOT NULL,
pors text NOT NULL,
paso text NOT NULL,
java text NOT NULL,
paye text NOT NULL,
dars text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE natije (
id tinyint(4) NOT NULL auto_increment,
name text NOT NULL,
paye text NOT NULL,
dars text NOT NULL,
azmo text NOT NULL,
idaz text NOT NULL,
nati text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE tut (
id tinyint(4) NOT NULL auto_increment,
title text NOT NULL,
body text NOT NULL,
dars text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE amoozgar (
id tinyint(4) NOT NULL auto_increment,
name text NOT NULL,
tozi text NOT NULL,
imag text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE news (
id tinyint(4) NOT NULL auto_increment,
title text NOT NULL,
date text NOT NULL,
matn text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
mysql_query("CREATE TABLE about (
id tinyint(4) NOT NULL auto_increment,
work text NOT NULL,
matn text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;");
$date = date("d");
mysql_query("INSERT INTO `stat` VALUES (1, '0', '0', '0', '$date');");
mysql_query("INSERT INTO matn (id,title,body ) VALUES ('1','index','Home Text' )");
mysql_query("INSERT INTO matn (id,title,body ) VALUES ('2','contact','contact Text' )");
mysql_query("INSERT INTO matn (id,title,body ) VALUES ('3','term','term Text' )");
mysql_query("INSERT INTO about (id,work,matn ) VALUES ('1','darbare','Darbare Text' )");
mysql_query("INSERT INTO about (id,work,matn ) VALUES ('2','emkanat','emkanat Text' )");
mysql_query("INSERT INTO about (id,work,matn ) VALUES ('3','contact','Tamas Text' )");
?>
پاسخ : ایجاد table در یک دیتابیس
عبارات داخل " " رو یکی یکی کپی کنید و توی قسمت sql پیست کنید و اجرا کنید .
قبلش روی دیتابیسی که میخواید کلیک کنید .
توی phpmyqdmin
پاسخ : ایجاد table در یک دیتابیس
این ارور رو می اره
کد:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM' at line 10
پاسخ : ایجاد table در یک دیتابیس
MyISAM رو به InnoDB تبدیل کنید
پاسخ : ایجاد table در یک دیتابیس
این ارور رو می ده
کد:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=InnoDB' at line 10
پاسخ : ایجاد table در یک دیتابیس
خیلی خوب مشکل اون رو حل کردم ظاهرا توی ورژن جدید TYPE تعریف نشده بود و از ENGINE استفاده می شه
اما الان یه مشکلی وجود داره وقتی که اسکریپت رو اجرا می کنم مشکلی توی اجرا نداره ولی اطلاعات رو توی دیتابیس ذخیره نمی کنه
و توی ارور لاگ توی سی پنل این ارور رو می نویسه
کد PHP:
[10-Dec-2012 07:13:46 UTC] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/vpsco/public_html/3/include/showpaye.php on line 5
[10-Dec-2012 07:13:46 UTC] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/vpsco/public_html/3/include/showpaye.php on line 14
و وقتی می رم توی محلی که گفته این خط ها رو نشون می ده (کل فایل PHP رو می زارم) (این همون فایل showpaye.php هست )
کد PHP:
<?php
include "config.php";
$paye13 = "";
$resul2 = mysql_query("SELECT * FROM paye order by id ASC")or die(mysql_error());
while($r=mysql_fetch_array($result)){
$name = $r["name"];
$id = $r["id"];
$paye13 .= "<div class=nx> <a href='?do=mobahese&shomare=$id' class=navx>$name</a></div>
";
}
$maghalat="";
$resul2 = mysql_query("SELECT * FROM cat order by id ASC")or die(mysql_error());
while($r=mysql_fetch_array($result)){
$name = $r["name"];
$id = $r["id"];
$maghalat .= "<div class=nx> <a href='?do=dars&shomare=$id' class=navx>$name</a></div>";
}
$rand = rand(1,10);
$sokhan = "<img src='images/sokhan/$rand.gif'>";
?>
مشکل از چی می تونه لاشه
با توجه به این که من از دستور های بالا برای ایجاد Table ها استفاده کردم ؟ نیاز دیگ ای هست؟
پاسخ : ایجاد table در یک دیتابیس
میشه بگید این سیستم چیه ؟
هر کی نوشته نابغه sql بوده .
دستور TYPE=MyISAM رو به ENGINE=MyISAM
احتمالا این بابا چیزی از ساختمان داده MySQL حالیش نبوده .
فیلد های username و password باید از نوع varchar 255 باشند نه text
number باید از نوع int یا bigint باشه .
همه چیو زده text بابا این چیه ؟؟؟؟؟
دارم به این فکر میکنم کد نویسیش چه جوری بوده . :-s
پاسخ : ایجاد table در یک دیتابیس
دقیقا نفهمیدم مشکل از چیه ولی مرتبا ارور رو از این فایل یعنی showpaye.php می گیره و بقیه رو درست کار می کنه
و من هم نفهمیدم مشکل از کجاست اصلا اونجا یوزر و پسورد وجود نداره !!!!
فقط نمی دونم فکر می کنم مشکل از این
کد PHP:
SELECT * FROM paye order by id ASC
می شه لطف کنید و بگید که منظور از کد بالا چی هست
و این کد بالا در حقیقت چه چیزی رو در Mysql چک یا ..... می کنه ؟
پاسخ : ایجاد table در یک دیتابیس
تموم رکورد های جدول paye رو برمیگردونه .
مشکل از اون نیست .
من میگم کلا از این اسکریپت استفاده نکن . B-)
این دستورات رو تغییر بده درست میشه .
کد PHP:
<?php
include "config.php";
$paye13 = "";
$result = mysql_query("SELECT * FROM paye order by id ASC")or die(mysql_error());
while($r=mysql_fetch_array($result)){
$name = $r["name"];
$id = $r["id"];
$paye13 .= "<div class=nx> <a href='?do=mobahese&shomare=$id' class=navx>$name</a></div>
";
}
$maghalat="";
$result = mysql_query("SELECT * FROM cat order by id ASC")or die(mysql_error());
while($r=mysql_fetch_array($result)){
$name = $r["name"];
$id = $r["id"];
$maghalat .= "<div class=nx> <a href='?do=dars&shomare=$id' class=navx>$name</a></div>";
}
$rand = rand(1,10);
$sokhan = "<img src='images/sokhan/$rand.gif'>";
?>
پاسخ : ایجاد table در یک دیتابیس
ببخشید شما چی رو تغییر دادید ؟