3

Here is the situation. I just know total number of columns the table test_table has but don't know their names(sounds strange but its true). Is there any way I can write UPDATE Query for all column values on basis of some ID(auto-increment primary key)?

To add row in this table, I did following which is working but don't have idea how to do it for UPDATE:

$newCols = $_POST['newRowCols'];
$query = "INSERT INTO test_table VALUES "."("."NULL";   
foreach($newCols as $col)
{
$query .= ",'$col'";
}   
$query.=")";
mysqli_query($con,$query);

Thanks.

4

1 回答 1

4

不,这是不可能的。information_schema但是您可以使用数据库获取列名:

SELECT 
  `ORDINAL_POSITION`,
  `COLUMN_NAME`
FROM `information_schema`.COLUMNS
WHERE
  `TABLE_SCHEMA` = $dbname
AND
  `TABLE_NAME` = $tablename
ORDER BY `ORDINAL_POSITION`
于 2013-07-25T22:59:08.917 回答