IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

五、MariaDB 插入查询

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

在本章中,我们将学习如何在表中插入数据。

将数据插入表需要INSERT命令。 该命令的一般语法是INSERT,后跟表名,字段和值。

查看下面给出的一般语法 –

INSERT INTO tablename (field,field2,...) VALUES (value, value2,...);

该语句需要对字符串值使用单引号或双引号。 语句的其他选项包括“INSERT … SET”语句,“INSERT … SELECT”语句和其他几个选项。

注意 - 出现在语句中的VALUES()函数仅适用于INSERT语句,如果在其他位置使用,则返回NULL。

存在两种执行操作的选项:使用命令行或使用PHP脚本。

命令提示符

在提示时,有许多方法来执行选择操作。 下面给出标准语句 –

belowmysql>
INSERT INTO products_tbl (ID_number, Nomenclature) VALUES (12345,
“Orbitron 4000”);
mysql> SHOW COLUMNS FROM products_tbl;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| ID_number   | int(5)      |      |     |         |       |
| Nomenclature| char(13)    |      |     |         |       |
+-------------+-------------+------+-----+---------+-------+

您可以插入多行 –

INSERT INTO products VALUES (1, “first row”), (2, “second row”);

您还可以使用SET子句 –

INSERT INTO products SELECT * FROM inventory WHERE status = 'available';

PHP插入脚本

在PHP函数中使用相同的“INSERT INTO …”语句来执行操作。 您将再次使用mysql_query()函数。

查看下面给出的示例 –

<?php
   if(isset($_POST['add'])) {
      $dbhost = 'localhost:3036';
      $dbuser = 'root';
      $dbpass = 'rootpassword';
      $conn = mysql_connect($dbhost, $dbuser, $dbpass);

      if(! $conn ) {
         die('Could not connect: ' . mysql_error());
      }

      if(! get_magic_quotes_gpc() ) {
         $product_name = addslashes ($_POST['product_name']);
         $product_manufacturer = addslashes ($_POST['product_name']);
      } else {
         $product_name = $_POST['product_name'];
         $product_manufacturer = $_POST['product_manufacturer'];
      }
      $ship_date = $_POST['ship_date'];
      $sql = "INSERT INTO products_tbl ".
         "(product_name,product_manufacturer, ship_date) ".
         "VALUES"."('$product_name','$product_manufacturer','$ship_date')";

      mysql_select_db('PRODUCTS');
      $retval = mysql_query( $sql, $conn );

      if(! $retval ) {
         die('Could not enter data: ' . mysql_error());
      }

      echo "Entered data successfully
";
      mysql_close($conn);
   }
?>

成功插入数据后,您将看到以下输出 –

mysql> Entered data successfully

您还将使用insert语句来合作验证语句,例如检查以确保正确的数据输入。 MariaDB包括许多选项,其中一些是自动的。


干货推荐

文章永久链接:https://tech.souyunku.com/?p=9778


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(96) 打赏



未经允许不得转载:搜云库技术团队 » 五、MariaDB 插入查询

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367