图中的mysql数据表如何建立外键连接?1005:Can't create table '某表'(errno: 150)
类中的两个方法,表名的参数等都正确输入了。publicfunctioncrttable(){$mysql_command2="createtable".$this->tb...
类中的两个方法,表名的参数等都正确输入了。
public function crttable()
{
$mysql_command2 ="create table ".$this->tbname."(id int not null auto_increment primary key ,inf0 tinyint(1),inf1 tinyint(1),inf2 tinyint(1), inf3 tinyint(1),inf4 tinyint(1),inf5 tinyint(1),inf6 tinyint(1),name char(15) not null) ENGINE = INNODB";
$result2=mysql_query($mysql_command2) or die ("failed to create table:".mysql_errno().":".mysql_error());
if($result2)
echo "table created successfully!"."<br>"; //creating concrete table "voteinfo"
else
echo "table creation failed."."<br>";
}
public function crttable1()
{
$mysql_command2 ="create table ".$this->tbname2." (nameb char(15) NOT NULL,tel int(12) NOT NULL,PRIMARY KEY (nameb,tel),FOREIGN KEY (nameb) REFERENCES ".$this->tbname." (name) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = INNODB";
$result2=mysql_query($mysql_command2) or die ("failed to create table:".mysql_errno().":".mysql_error());
if($result2)
echo "table created successfully!"."<br>"; //creating concrete table "voteradd"
else
echo "table creation failed."."<br>";
}
http://img165.poco.cn/mypoco/myphoto/20110916/12/5636976620110916122927018.png
正确为这两个表建立外键连接的语句应该怎么写啊?求高手指正中! 展开
public function crttable()
{
$mysql_command2 ="create table ".$this->tbname."(id int not null auto_increment primary key ,inf0 tinyint(1),inf1 tinyint(1),inf2 tinyint(1), inf3 tinyint(1),inf4 tinyint(1),inf5 tinyint(1),inf6 tinyint(1),name char(15) not null) ENGINE = INNODB";
$result2=mysql_query($mysql_command2) or die ("failed to create table:".mysql_errno().":".mysql_error());
if($result2)
echo "table created successfully!"."<br>"; //creating concrete table "voteinfo"
else
echo "table creation failed."."<br>";
}
public function crttable1()
{
$mysql_command2 ="create table ".$this->tbname2." (nameb char(15) NOT NULL,tel int(12) NOT NULL,PRIMARY KEY (nameb,tel),FOREIGN KEY (nameb) REFERENCES ".$this->tbname." (name) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = INNODB";
$result2=mysql_query($mysql_command2) or die ("failed to create table:".mysql_errno().":".mysql_error());
if($result2)
echo "table created successfully!"."<br>"; //creating concrete table "voteradd"
else
echo "table creation failed."."<br>";
}
http://img165.poco.cn/mypoco/myphoto/20110916/12/5636976620110916122927018.png
正确为这两个表建立外键连接的语句应该怎么写啊?求高手指正中! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询