我與數據庫連接的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 –