PHP mysqli returns wrong columns

2019-02-28 14:27发布

I'm writing a simple PHP cgi program that needs to use MySql. I started with two columns in the players table, and my SELECT worked fine. I have added another column since then called class_id. When I do a SELECT now, I get three entries back in $row, but the third entry is called players instead of class_id.

$sql = "SELECT * FROM players";
$result = $conn->query($sql);
while( $row = $result->fetch_assoc() ){
  do something
}

The schema:

DROP TABLE IF EXISTS `asrleague`.`players`;
CREATE TABLE  `asrleague`.`players` (
  `player_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `kgs_handle` varchar(40) NOT NULL,
  `class_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`player_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

Is PHP caching info about the table somewhere, and I need to get it to refresh somehow?

I'm also seeing this warning, which has been there all the time:

<b>Warning</b>:  mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: Headers and client library minor version mismatch. Headers:50145 Library:50018 in ...

I'm not sure if that's related or not, but it was there before the problem started.

标签: php mysql mysqli
1条回答
太酷不给撩
2楼-- · 2019-02-28 15:15

Some Googling on your error message, gives those interesting threads:

Seems that a reinstallation of PHP could be necessary.

Quoting an answer (anishmsry's) from the first link (bold is from me):

Hi bmcgill... i had installed php, mysql and apache some months ago in my computer following the instructions from kevin's book. and there was no problem. everything was working fine.

i bought a new computer last week and installed the latest versions in the new computer. after installing and running it. i got the error which u got: Warning: mysqli_connect() [function.mysqli-connect]: Headers and client library minor version mismatch. Headers:50051 Library:50145

i reinstalled everything and again i was receiving the same error. i had the same conf for mysql, php and apache as u've mentioned.

i uninstalled apache and php. and installed the earlier versions which i was using: apache- 2.2.11 and php-5.3.0. this time everything was working fine and there was no error

well it just worked like that for me. that's why i'm telling. i don't know why it worked now.

i was searching about this issue in net, and in a forum in mysql's website i found that some other person had this problem with a much earlier versions. he reinstalled php and the problem was solved.

查看更多
登录 后发表回答