类stdClass的对象无法转换为字符串

时间:2016-08-11 14:41:18

标签: php

我正在用angular和php构建一个项目,我试图从phpmyadmin表中删除一行,我在php中有这个错误。有人可以查看我的代码吗?

  <?php
     header('Content-Type: text/html; charset=utf-8');
    $connect=mysqli_connect("localhost", "root", "", "hamatkin");

      include_once 'file.php';
    mysqli_query($connect,"SET character_set_client = utf8");
    mysqli_query($connect,"SET character_set_connection = utf8");
    mysqli_query($connect,"SET character_set_results = utf8");
    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $data = json_decode(file_get_contents("php://input"));


     $id = $data->id;
    $del = "DELETE FROM file WHERE id=".$id;

       mysqli_query($connect, $del);

    $newURL = "/hamatkin/#/allPriceOffers";
    header('Location: '.$newURL);
    ?>

使用var_dump($ data)后:

<pre class='xdebug-var-dump' dir='ltr'>
<small>C:\wamp64\www\hamatkin\api\customers-tab\delete-priceOffer.php:43:</small>
<b>object</b>(<i>stdClass</i>)[<i>2</i>]
  <i>public</i> 'id' <font color='#888a85'>=&gt;</font> 
    <b>object</b>(<i>stdClass</i>)[<i>3</i>]
      <i>public</i> 'created' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'2016-08-11 15:19:14'</font> <i>(length=19)</i>
      <i>public</i> 'customer_id' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'85'</font> <i>(length=2)</i>
      <i>public</i> 'full_name' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'אלכס שפירא'</font> <i>(length=19)</i>
      <i>public</i> 'city' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'תל-אביב'</font> <i>(length=13)</i>
      <i>public</i> 'phone' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'545928875'</font> <i>(length=9)</i>
      <i>public</i> 'name' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'קורות ×—×™×™×.zip'</font> <i>(length=46)</i>

2 个答案:

答案 0 :(得分:1)

试试这个:

$id = intval($data->id->customer_id); 

新编辑有帮助吗?

答案 1 :(得分:1)

json_decode($data, true)
  

混合 json_decode (字符串$ json [,bool $ assoc = false [,int $ depth = 512 [,int $ options = 0]]])

     

accs 当为TRUE时,返回的对象将转换为关联数组。

请参阅文档here