我在将最后一个ID插入表格时遇到问题,因为它返回空白。 我研究了堆栈,但我找不到解决方案。
在DB中包含信息的脚本:
if ( isset( $_GET['create'] ) )
{
if ( isset( $_POST['dep_nome'] ) )
{
$noticia_title = trim( $_POST['dep_nome'] );
$noticia_content = trim( $_POST['dep_content'] );
$db->query( "insert into departamentos (dep_nome, dep_content) values ('$dep_nome','$dep_content');" );
$dep_id = $db->insert_id;
@header( "Location: departamentos.php?edit=$dep_id" );
}
}
类包括insert_id(COMMENT CLASS INSERT ID)
<?php
Class mysql{
public $query;
public $data;
public $result;
public $rows;
public $insert_id;
protected $config;
protected $host;
protected $port;
protected $user;
protected $pass;
protected $dbname;
protected $con;
public function __construct()
{
try
{
#array com dados do banco
include 'database.conf.php';
global $databases;
$this->config = $databases['local'];
# Recupera os dados de conexao do config
$this->dbname = $this->config['dbname'];
$this->host = $this->config['host'];
$this->port = $this->config['port'];
$this->user = $this->config['user'];
$this->pass = $this->config['password'];
# instancia e retorna objeto
$this->con = $this->con = @mysqli_connect( "$this->host", "$this->user", "$this->pass","$this->dbname");
//@mysql_select_db( "$this->dbname" );
if ( !$this->con )
{
throw new Exception( "Falha na conexão MySql com o banco [$this->dbname] em database.conf.php" );
}
else
{
return $this->con;
}
}
catch ( Exception $e )
{
echo $e->getMessage();
exit;
}
return $this;
}
public function query($query = '' )
{
try
{
if ( $query == '' )
{
throw new Exception( 'mysql query: A query deve ser informada como parâmetro do método.' );
}
else
{
$this->query = $query;
$this->result = mysqli_query($this->con, $this->query );
$this->insert_id = mysqli_insert_id($this->con);//COMMENT CLASS INSERT ID
}
}
catch ( Exception $e )
{
echo $e->getMessage();
exit;
}
return $this;
}
public function fetchAll()
{
$this->data = "";
$this->rows = 0;
while ( $row = @mysqli_fetch_array( $this->result, MYSQLI_ASSOC ) )
{
$this->data[] = $row;
}
if ( isset( $this->data[0] ) )
{
$this->rows = count( $this->data );
}
return $this->data;
}
public function rowCount()
{
return @mysqli_affected_rows();
}
public function limit( $limit, $offset )
{
return "LIMIT " . ( int ) $limit . "," . ( int ) $offset;
}
}
/ *结束文件* /
任何人都可以帮助我吗? GET中的结果只是“departamentos.php?edit =”,并且没有返回通过$ db-&gt; insert_id输入的ID。
我已经查看了文档但无法解决。