我试图用下面的代码从数据库中拉出一些记录,但是我的代码末尾的echo json_encode($contacts);
没有打印任何东西。上面没有任何echo
。json_encode没有得到echo'ed
<?php
require_once(dirname(__FILE__).'/ConnectionInfo.php');
//Set up our connection
$connectionInfo = new ConnectionInfo();
$connectionInfo->GetConnection();
if (!$connectionInfo->conn)
{
//Connection failed
echo 'No Connection';
}
else
{
//Create query to retrieve all contacts
$query = 'SELECT Numero_Leccion,Titulo_Leccion,Ejemplo_Leccion FROM leccion';
$stmt = sqlsrv_query($connectionInfo->conn, $query);
if (!$stmt)
{
//Query failed
echo 'Query failed';
}
else
{
$contacts = array(); //Create an array to hold all of the contacts
//Query successful, begin putting each contact into an array of contacts
while ($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC)) //While there are still contacts
{
//Create an associative array to hold the current contact
//the names must match exactly the property names in the contact class in our C# code.
$contact = array("Numero_Leccion"=>$row['Numero_Leccion'],"Titulo_Leccion"=>$row['Titulo_Leccion'],"Ejemplo_Leccion"=>$row['Ejemplo_Leccion']);
//Add the contact to the contacts array
array_push($contacts, $contact);
}
//Echo out the contacts array in JSON format
echo json_encode($contacts);
}
}
?>
而你的问题是什么?它什么都不输出,或者'NULL'或者..? – kero
它回声没有什么,如果我放置和回声json_encode($ contatcts)上面的常规回声如果得到那里。并且输出变为空白。另一件事,如果我回应这个“echo json_encode($ contact)”它打印该数组 –
我的查询实际上从数据库中检索到4条记录,我的代码没有回显它。 –