i made php code with database connection named test.php like below :
<?
$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();
?>
it works when i call via browser http://localhost/learn/test.php and data inserted to my database
but when i running in 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();'
no data inserted. update now i tes to eval($code); seems OKAY in windows but not in LINUX