未定义索引:___mysqli_ston

Undefined index: ___mysqli_ston(未定义索引:___mysqli_ston)
本文介绍了未定义索引:___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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

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 的问题)