简体   繁体   English

CodeIgniter:第一个查询成功运行,第二个未能更改数据库。 相同的值,不同的表

[英]CodeIgniter: first query runs successfully, second fails to change the database. Same value, different tables

$customer_number is being grabbed from an xml file and, due to new code I've added, being sanitized to ensure that it is indeed an INT (I was just trying to narrow down causes). $ customer_number是从xml文件中获取的,由于我添加了新代码,因此需要对其进行清理以确保它确实是一个INT(我只是想缩小原因)。

It's sanitized then stored in aforementioned variable name (If I echo this variable, I do get a number displayed). 将其清除后存储在上述变量名中(如果我回显此变量,则会显示一个数字)。 It is then placed into two arrays for two separate queries targeting the exp_store_orders and exp_members tables respectively. 然后将其放置在两个数组中,以分别针对exp_store_orders和exp_members表进行两个单独的查询。

The first query executes without a hitch. 第一个查询执行顺利。 account_number is updated just fine with the value of $customer_number within the exp_store_order table. 使用exp_store_order表中的$ customer_number值可以很好地更新account_number。

However, the second smaller query fails to update the account_number field in the exp_members table at all. 但是,第二个较小的查询根本无法更新exp_members表中的account_number字段。

if I replace the variable in the $updateData2 array with a simple number, such as '1', the second query does what it is supposed to do. 如果我将$ updateData2数组中的变量替换为一个简单的数字(例如“ 1”),则第二个查询将执行应做的事情。 The account_number field is then updated in exp_members. 然后,使用exp_members更新account_number字段。

I don't really get what's going on truth be told.. I don't get how it can clearly be an INT and work in the first array\\first query but do absolutely nothing (with no error!) in the second. 我并没有真正知道发生了什么。我不知道如何将它清楚地当作INT并在第一个array \\ first查询中工作,但在第二个数组中却绝对不做任何操作(没有错误!)。

Any help would be greatly appreciated. 任何帮助将不胜感激。

//searches for and grabs all xml files within the directory. Parses all elements and stores values in variables.
foreach(glob("/random/directory/listing/*xml") as $filename) {
    $xml= simplexml_load_file($filename);

    $order_id = $xml->order_id; 
    $hash = $xml->hash; 
    $timestamp = $xml->timestamp;
    $date = $xml->date;
    $time = $xml->time;
    $customer_number = $xml->customer_number;
    $customer_number = filter_var($customer_number, FILTER_SANITIZE_NUMBER_INT);
    $member_id = $xml->member_id;
    $shipping_account = $xml->shipping_account;
    $shipping_carrier = $xml->shipping_carrier;
    $shipping_tracking = $xml->shipping_tracking;
    $response = $xml->response;
    $response = filter_var($response, FILTER_SANITIZE_STRING);
    $status_update = time();



   //places variables within arrays to be fed into queries.
   $updateData = array(
       'response' => "$response",
       'order_custom2' => "$shipping_account",
       'order_custom3' => "$shipping_carrier",
       'shipping_tracking' => "$shipping_tracking",
       'order_completed_date' => "$timestamp",
       'order_status_updated' => "$status_update",
       'order_status_name' => "Shipping",
       'account_number' => "$customer_number"
   );

   $updateData2 = array(
       'account_number' => "$customer_number"
   );

   //update database with values from XML file, specifically the exp_store_orders and exp_members tables.
   $qry = $this->EE->db->where('id = '.$order_id.'')
                        ->update('exp_store_orders', $updateData); 

   $qry2 = $this->EE->db->where('member_id = '.$member_id.'')
                        ->update('exp_members', $updateData2); 

   //remove files from directory.
   //unlink($filename);
 }

Edit: When I change the code and do this: 编辑:当我更改代码并执行以下操作:

$updateData2 = array(
       'AS400_account_number' => $xml->customer_number //$customer_number
   );

I get the following error: 我收到以下错误:

Error Number: 1064 错误号:1064

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE member_id = 1' at line 1 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ WHERE member_id = 1”附近使用

UPDATE exp_members SET AS400_account_number = WHERE member_id = 1 更新exp_members SET AS400_account_number = WHERE member_id = 1

   $updateData2 = array(
       'account_number' => $customer_number
   );

Remove quotes around $customer_number 删除$ customer_number周围的引号

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 只能插入第一个和第二个值,其他值不能插入数据库。 如何解决呢? - only can insert first and second value other value cannot insert in database. how to solve this? 一个数据库中具有不同字符编码的表。 教义问题 - Tables with different character encodings in one database. Doctrine issue Codeigniter从数据库中加载第二个不同的数据数组,第二个依赖于第一个,并加载到视图中 - Codeigniter loading two different data array from a database with the second one is dependent with the first one and load into a view 从两个不同的表但相同的数据库中选择 SQL 查询 - Select SQL query from two different tables but same database Codeigniter第二个没有对象的数据库连接查询 - Codeigniter second database connection query without object 根据第一选择值从数据库填充第二选择(车辆模型)-Codeigniter - Populating second select from database based on first select value (vehicle models) - codeigniter 消息:成功创建表,但只有第一个表出现在数据库中 - message: successfully created tables but only the first one appears in database 脚本的第二个实例运行与第一个实例完全相同的代码 - Second instance of script runs the exact same code as the first one CodeIgniter 正在数据库中生成多个会话。 为什么? - CodeIgniter is generating multiple sessions in the database. Why? CodeIgniter - 从数据库中存储和读取语言。 - CodeIgniter - Store and read Language from database.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM