测试是否已存在某些内容(Testing if something already exists)

编程入门 行业动态 更新时间:2024-10-26 00:25:24
测试是否已存在某些内容(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.

更多推荐

本文发布于:2023-07-26 02:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269912.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   内容   exists   Testing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!