---
title: "PHP中source #N问题"
author: "mywebcode"
date: "2013-12-01T01:10:00Z"
tags: []
slug: "php-source-n"
draft: false
lastmod: "2014-04-30T09:04:30Z"
id: 2057495
url: "https://mywebcode.iteye.com/blog/2057495"
---

最近写PHP里面的查询经常会遇到source #4或者source#5这样的问题，也就是通过mysql\_query($sql1)进行一段查询的操作，返回的结果不是想要的字段而是source，去网上查了一些资料都说是什么‘资源’的问题，虽然对于出现这种情况的原理还是不甚了解，但是解决方案是有了，下面是解决这个问题的代码：

```
$result2 = mysql_query("SELECT imagePath FROM anypaiInfo WHERE schoolId = 1 AND id = $random ");
$row = mysql_fetch_object($result2);
$imageUrl = $row->imagePath;
```

如上述代码所示，第一段的查询过后，用mysql\_fetch\_object的函数从结果中获取一行作为对象，然后在这一行里面把想要的字段获取出来。![疑问](http://static.blog.csdn.net/xheditor/xheditor_emot/default/doubt.gif)不过出现这个问题的原因还在纠结中。