<tfoot id='QOilU'></tfoot>

<small id='QOilU'></small><noframes id='QOilU'>

    • <bdo id='QOilU'></bdo><ul id='QOilU'></ul>

      <i id='QOilU'><tr id='QOilU'><dt id='QOilU'><q id='QOilU'><span id='QOilU'><b id='QOilU'><form id='QOilU'><ins id='QOilU'></ins><ul id='QOilU'></ul><sub id='QOilU'></sub></form><legend id='QOilU'></legend><bdo id='QOilU'><pre id='QOilU'><center id='QOilU'></center></pre></bdo></b><th id='QOilU'></th></span></q></dt></tr></i><div id='QOilU'><tfoot id='QOilU'></tfoot><dl id='QOilU'><fieldset id='QOilU'></fieldset></dl></div>
    1. <legend id='QOilU'><style id='QOilU'><dir id='QOilU'><q id='QOilU'></q></dir></style></legend>
      1. 将 JSON 字符串保存到 MySQL 数据库

        Saving JSON string to MySQL database(将 JSON 字符串保存到 MySQL 数据库)
          <tbody id='1CcfL'></tbody>
      2. <i id='1CcfL'><tr id='1CcfL'><dt id='1CcfL'><q id='1CcfL'><span id='1CcfL'><b id='1CcfL'><form id='1CcfL'><ins id='1CcfL'></ins><ul id='1CcfL'></ul><sub id='1CcfL'></sub></form><legend id='1CcfL'></legend><bdo id='1CcfL'><pre id='1CcfL'><center id='1CcfL'></center></pre></bdo></b><th id='1CcfL'></th></span></q></dt></tr></i><div id='1CcfL'><tfoot id='1CcfL'></tfoot><dl id='1CcfL'><fieldset id='1CcfL'></fieldset></dl></div>

            <small id='1CcfL'></small><noframes id='1CcfL'>

            • <legend id='1CcfL'><style id='1CcfL'><dir id='1CcfL'><q id='1CcfL'></q></dir></style></legend>
              • <tfoot id='1CcfL'></tfoot>

                  <bdo id='1CcfL'></bdo><ul id='1CcfL'></ul>
                  本文介绍了将 JSON 字符串保存到 MySQL 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 JSON 字符串

                  I have a JSON string with me

                  {"name":"jack","school":"colorado state","city":"NJ","id":null}
                  

                  我需要将它保存在数据库中.我怎么能这样做?

                  I need it to be saved in the Database. How could i do this ?

                  我的 PHP 代码(我只建立了与 MySQL 的连接,但我无法保存记录)

                  My PHP code (I have only establish the connection to MySQL, but i am unable to save the records)

                     <?php
                      // the MySQL Connection
                      mysql_connect("localhost", "username", "pwd") or die(mysql_error());
                      mysql_select_db("studentdatabase") or die(mysql_error());
                  
                      // Insert statement
                  
                      mysql_query("INSERT INTO student
                      (name, school,city) VALUES(------------------------- ) ") // (How to write this)
                      or die(mysql_error());  
                  
                  
                      echo "Data Inserted or failed";
                  
                      ?>
                  

                  推荐答案

                  我们将使用 json_decode json_decode 文档

                  也一定要逃跑!下面是我的做法...

                  Also be sure to escape! here's how I would do it below...

                  /* create a connection */
                  $mysqli = new mysqli("localhost", "root", null, "yourDatabase");
                  
                  /* check connection */
                  if (mysqli_connect_errno()) {
                      printf("Connect failed: %s
                  ", mysqli_connect_error());
                      exit();
                  }
                  
                  /* let's say we're grabbing this from an HTTP GET or HTTP POST variable called jsonGiven... */
                  $jsonString = $_REQUEST['jsonGiven'];
                  /* but for the sake of an example let's just set the string here */
                  $jsonString = '{"name":"jack","school":"colorado state","city":"NJ","id":null}
                  ';
                  
                  /* use json_decode to create an array from json */
                  $jsonArray = json_decode($jsonString, true);
                  
                  /* create a prepared statement */
                  if ($stmt = $mysqli->prepare('INSERT INTO test131 (name, school, city, id) VALUES (?,?,?,?)')) {
                  
                      /* bind parameters for markers */
                      $stmt->bind_param("ssss", $jsonArray['name'], $jsonArray['school'], $jsonArray['city'], $jsonArray['id']);
                  
                      /* execute query */
                      $stmt->execute();
                  
                      /* close statement */
                      $stmt->close();
                  }
                  
                  /* close connection */
                  $mysqli->close();
                  

                  希望这会有所帮助!

                  这篇关于将 JSON 字符串保存到 MySQL 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <tfoot id='M8GEM'></tfoot>
                    <legend id='M8GEM'><style id='M8GEM'><dir id='M8GEM'><q id='M8GEM'></q></dir></style></legend>

                          <tbody id='M8GEM'></tbody>
                        <i id='M8GEM'><tr id='M8GEM'><dt id='M8GEM'><q id='M8GEM'><span id='M8GEM'><b id='M8GEM'><form id='M8GEM'><ins id='M8GEM'></ins><ul id='M8GEM'></ul><sub id='M8GEM'></sub></form><legend id='M8GEM'></legend><bdo id='M8GEM'><pre id='M8GEM'><center id='M8GEM'></center></pre></bdo></b><th id='M8GEM'></th></span></q></dt></tr></i><div id='M8GEM'><tfoot id='M8GEM'></tfoot><dl id='M8GEM'><fieldset id='M8GEM'></fieldset></dl></div>

                            <bdo id='M8GEM'></bdo><ul id='M8GEM'></ul>

                            <small id='M8GEM'></small><noframes id='M8GEM'>