-4

为什么在 $columnArray[]... 行上出现意外的 ']' 错误?

<?php

$con=mysqli_connect("localhost","user","password","test");
if (mysqli_connect_errno($con))  { echo "Failed to connect to MySQL: " . mysqli_connect_error();}

 $sql = "SELECT column_comment,column_name FROM information_schema.columns  
  WHERE table_name = 'mytable'; 
 $query = mysqli_query($con,$sql) or die(mysql_error());
 $columnArray = array();

 $columnArray = array();

 while($result = mysqli_fetch_array($query)){


   $columnArray[] = array('column_comment' => $result['column_comment'], 'column_name' => $result['column_name']);

 }

PHP 解析错误:语法错误,意外的 ']',需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或数字 (T_NUM_STRING)

4

3 回答 3

4

语法高亮显示错误。您缺少结束语:

 $sql = "SELECT column_comment,column_name FROM information_schema.columns  
  WHERE table_name = 'mytable';

应该

 $sql = "SELECT column_comment,column_name FROM information_schema.columns  
  WHERE table_name = 'mytable'";
于 2013-08-24T22:11:13.173 回答
2

甚至 StackOverflow 的语法高亮显示你的代码被破坏了。您需要关闭查询字符串,而不是:

$sql = "SELECT column_comment,column_name FROM information_schema.columns 
        WHERE table_name = 'mytable'; 

你需要:

$sql = "SELECT column_comment,column_name FROM information_schema.columns  
        WHERE table_name = 'mytable'"; 

让自己比记事本更好:)

于 2013-08-24T22:12:03.543 回答
1

用这个替换旧查询..

 $sql = "SELECT column_comment,column_name FROM information_schema.columns WHERE table_name = 'mytable'"; 
于 2013-08-24T22:15:08.863 回答