<legend id='46Hfx'><style id='46Hfx'><dir id='46Hfx'><q id='46Hfx'></q></dir></style></legend>
      <bdo id='46Hfx'></bdo><ul id='46Hfx'></ul>
  1. <tfoot id='46Hfx'></tfoot>

      <small id='46Hfx'></small><noframes id='46Hfx'>

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

      未定义索引:___mysqli_ston

      时间:2023-09-24

        1. <legend id='L7ihZ'><style id='L7ihZ'><dir id='L7ihZ'><q id='L7ihZ'></q></dir></style></legend>

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

          <tfoot id='L7ihZ'></tfoot>
              <bdo id='L7ihZ'></bdo><ul id='L7ihZ'></ul>

                <tbody id='L7ihZ'></tbody>
              • <i id='L7ihZ'><tr id='L7ihZ'><dt id='L7ihZ'><q id='L7ihZ'><span id='L7ihZ'><b id='L7ihZ'><form id='L7ihZ'><ins id='L7ihZ'></ins><ul id='L7ihZ'></ul><sub id='L7ihZ'></sub></form><legend id='L7ihZ'></legend><bdo id='L7ihZ'><pre id='L7ihZ'><center id='L7ihZ'></center></pre></bdo></b><th id='L7ihZ'></th></span></q></dt></tr></i><div id='L7ihZ'><tfoot id='L7ihZ'></tfoot><dl id='L7ihZ'><fieldset id='L7ihZ'></fieldset></dl></div>
                本文介绍了未定义索引:___mysqli_ston的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试将一些 json 数据从文件解析到 mysql 数据库中.我的原始代码如下:

                I am trying to parse some json data, into a mysql database, from a file. My original code was as follows:

                <?php
                $response = array();
                $res=array();
                $json = file_get_contents('C:UsersRichardDesktop	est.json');
                
                if($json!=null){
                $decoded=json_decode($json,true);
                //$decode= var_dump($decoded);
                //$ss=$decode["array"];
                //echo $decoded['number'];
                
                if(is_array($decoded["configurationItems"]))
                {
                foreach($decoded["configurationItems"] as $configurationItems)
                //for($i=0;$i>sizeof($decoded["configurationItems"]);$i++)
                
                 {
                
                
                $configurationItemVersion=$configurationItems["configurationItemVersion"];
                echo "<br />","configurationItemVersion:",$configurationItemVersion,"<br    />";
                
                $configurationItemCaptureTime=$configurationItems["configurationItemCaptureTime"];
                echo "configurationItemCaptureTime:",$configurationItemCaptureTime,"<br />";
                
                $configurationStateId=$configurationItems["configurationStateId"];
                echo "configurationStateId:",$configurationStateId,"<br />";
                
                
                 $result = mysql_query("INSERT INTO configuration_item(configurationItemVersion,configurationItemCaptureTime,configurationStateId)
                
                
                VALUES('$configurationItemVersion','$configurationItemCaptureTime','$configurationStateId')")or die("Insert Failed ".mysql_error());;
                
                }// check if row inserted or not
                if ($result) {
                    // successfully inserted into database
                    $response["code"] = 1;
                    $response["message"] = "successfully stored";
                
                    // echoing JSON response
                    echo json_encode($response);
                } else {
                    // failed to insert row
                    $response["code"] = 2;
                    $response["message"] = "Oops! An error occurred.";
                
                    // echoing JSON response
                    echo json_encode($response);
                }
                
                }
                }
                

                ?>

                由于被贬低而失败;因此,我没有更改错误处理程序以忽略这一点(非常糟糕的做法),而是选择使用此处提供的便捷转换工具转换为 mysqli:https://github.com/philip/MySQLConverterTool

                which failed due to being depricated; so rather than altering the error handler to ignore this (really bad practice), I opted to convert to mysqli using a handy conversion tool sourced here : https://github.com/philip/MySQLConverterTool

                我在上述代码上运行转换器并生成以下内容:

                I ran the converter on the aforementioned code and it generated the following:

                <?php 
                $response = array(); 
                $res=array(); 
                $json = file_get_contents('C:UsersRichardDesktop	est.json'); 
                
                if($json!=null){ 
                $decoded=json_decode($json,true); 
                //$decode= var_dump($decoded); 
                //$ss=$decode["array"]; 
                //echo $decoded['number']; 
                
                if(is_array($decoded["configurationItems"])) 
                { 
                foreach($decoded["configurationItems"] as $configurationItems) 
                //for($i=0;$i>sizeof($decoded["configurationItems"]);$i++) 
                
                 { 
                
                
                $configurationItemVersion=$configurationItems["configurationItemVersion"]; 
                echo "<br />","configurationItemVersion:",$configurationItemVersion,"<br />"; 
                
                $configurationItemCaptureTime=$configurationItems["configurationItemCaptureTime"]; 
                echo "configurationItemCaptureTime:",$configurationItemCaptureTime,"<br />"; 
                
                $configurationStateId=$configurationItems["configurationStateId"]; 
                echo "configurationStateId:",$configurationStateId,"<br />"; 
                
                
                $result = mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO     configuration_item(configurationItemVersion,configurationItemCaptureTime,configurationStateId) 
                
                
                VALUES('$configurationItemVersion','$configurationItemCaptureTime','$configurationStateId')")or die("Insert Failed ".((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error(
                 "]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));; 
                
                }// check if row inserted or not 
                if ($result) { 
                    // successfully inserted into database 
                    $response["code"] = 1; 
                    $response["message"] = "successfully stored"; 
                
                    // echoing JSON response 
                    echo json_encode($response); 
                } else { 
                    // failed to insert row 
                    $response["code"] = 2; 
                    $response["message"] = "Oops! An error occurred."; 
                
                    // echoing JSON response 
                    echo json_encode($response); 
                } 
                
                } 
                } 
                
                
                
                ?> 
                

                在运行此代码时,我收到标题中的错误消息(未定义索引:___mysqli_ston)并且不知道如何修复它,任何帮助将不胜感激.

                upon running this code I get the error message in the title (Undefined index: ___mysqli_ston) and have no idea how to fix it, any help would be much appreciated.

                ps 我正在使用 laravel 框架,如果这有所作为或开辟了其他解决方案.

                ps I am using the laravel framework if that makes a difference or opens up other solutions.

                我现在知道错误与我没有数据库连接字符串有关,即 $GLOBALS["___mysqli_ston 是由生成器生成的.

                I now know that the error relates to the fact that I have no database connection string ie $GLOBALS["___mysqli_ston is generated by the generator.

                据我了解,laravel 负责在其 mvc 架构中定义数据库连接,因此不需要重新定义.考虑到这一点,我的代码会是什么样子?

                it was my understanding that laravel took care of defining the database connection in its mvc architecture and therefore this does not need to be redefined. with that in mind what would my code look like ?

                推荐答案

                你一定已经用这样的东西连接到 mysql

                you must have connected to mysql using something like this

                $con=mysqli_connect("localhost","my_user","my_password","my_db");
                

                替换你的这一行

                $result = mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO     configuration_item(configurationItemVersion,configurationItemCaptureTime,configurationStateId) 
                

                有了这个

                $result = mysqli_query($con, "INSERT INTO     configuration_item(configurationItemVersion,configurationItemCaptureTime,configurationStateId) 
                

                这篇关于未定义索引:___mysqli_ston的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:mysqli_real_escape_string() 期望参数 1 是 mysqli,布尔值 下一篇:mysqli_real_escape_string() 需要 2 个参数,1 个给定致

                相关文章

                最新文章

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

                    <bdo id='3jK1t'></bdo><ul id='3jK1t'></ul>

                  1. <legend id='3jK1t'><style id='3jK1t'><dir id='3jK1t'><q id='3jK1t'></q></dir></style></legend>
                  2. <tfoot id='3jK1t'></tfoot>
                  3. <small id='3jK1t'></small><noframes id='3jK1t'>