我与数据库连接的PHP代码名为test.php的象下面这样:PHP代码在PHP不行CLI
<?
$mysqli = new mysqli("localhost","root","","monster");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* return name of current default database */
if ($result = $mysqli->query("INSERT INTO `earth` (`monster_id`, `type`, `name`) VALUES
(NULL, 'defender', 'tortoise')
")) {
$row = $result->fetch_row();
printf("Default database is %s.\n", $row[0]);
$result->close();
}
$mysqli->close();
?>
它工作时,我通过插入到我的数据库浏览器http://localhost/learn/test.php
和数据呼叫
但当我运行在PHP CLI
php -r ' $mysqli = new mysqli("localhost","root","","monster");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* return name of current default database */
if ($result = $mysqli->query("INSERT INTO `earth` (`monster_id`, `type`, `name`) VALUES
(NULL, 'defender', 'tortoise')
")) {
$row = $result->fetch_row();
printf("Default database is %s.\n", $row[0]);
$result->close();
}
$mysqli->close();'
没有插入数据。 更新现在我试用eval($ code);似乎OKAY在Windows中,但不是在LINUX
什么样的错误你得到些什么? –
语法高亮显示似乎认为你有一个报价逃跑问题.. – Ben
现在我试用eval($ code); (NULL,\'defender \',\'tortoise \') 到 (NULL,\“defender \”,\“tortoise \”)看起来OKAY在windows中却没有在LINUX –