已经发布了几个关于依赖注入的具体问题的问题,例如何时使用它以及它有哪些框架.然而,
什么是依赖注入以及何时/为什么应该或不应该使用它?
language-agnostic design-patterns dependency-injection terminology
我有以下代码.mysqli_insert_id()(在本例中为"$ last_row"),应该返回表的最后一行,总是返回0.为什么会这样?
<?php
include('connect-db.php');
$submit_date = date("Ymd");
$content = mysqli_real_escape_string($connection, htmlspecialchars($_POST['editor']));
$ip_address = $_SERVER['REMOTE_ADDR'];
$last_row = mysqli_insert_id($connection);
if ($content != '') {
$sql = "INSERT INTO source ( track_id, submit_date, ip, content) VALUES ('$last_row', '$submit_date','$ip_address','$content')";
if (!mysqli_query($connection,$sql))
{
die('Error: ' . mysqli_error($connection));
}
echo $last_row;
mysqli_close($connection);
}
?>
Run Code Online (Sandbox Code Playgroud)