测试是否已存在某些内容(Testing if something already exists)
我正在努力为我的课程学习更多的分数,我的老师说这会有所帮助。 在创建变量或表等时,我想知道如何对其进行编码,以便如果它已经存在则不会运行代码。
$sql2 = "CREATE TABLE referee(refereeID INT (5) NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20))"; if (mysqli_query($link, $sql)){ echo "Table created successfully"; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }I am trying to pick up a few more marks for my coursework and my teacher said that this will help. When creating a variable or table etc, I want to know how I can code it so that if it already exists it doesn't run the code.
$sql2 = "CREATE TABLE referee(refereeID INT (5) NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20))"; if (mysqli_query($link, $sql)){ echo "Table created successfully"; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }最满意答案
您可以尝试使用此查询
$sql = "CREATE TABLE IF NOT EXISTS `referee` ( `refereeID` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL default '', PRIMARY KEY (`refereeID`) )";这将检查是否有任何这样的表在数据库中。
希望这可以帮助。
You can try with this query
$sql = "CREATE TABLE IF NOT EXISTS `referee` ( `refereeID` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL default '', PRIMARY KEY (`refereeID`) )";This checks to see if any table like this is in the database.
Hope this helps.
更多推荐
发布评论