Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert bug #149

Closed
dayrui opened this issue Jul 6, 2016 · 9 comments
Closed

insert bug #149

dayrui opened this issue Jul 6, 2016 · 9 comments

Comments

@dayrui
Copy link

dayrui commented Jul 6, 2016

$rt = $this->db->table('admin_menu')->insert(array(
                    'pid' => 0,
                    'name' => $top['name'],
                    'uri' => $top['uri'] ?? '',
                    'url' => $top['url'] ?? '',
                    'mark' => $top['mark'] ?? '',
                    'icon' => $top['icon'] ?? '',
                    'hidden' => $top['hidden'] ?? 0,
                    'displayorder' => $top['displayorder'] ?? 0,
                ));
                print_r($rt);

return:

CodeIgniter\Database\MySQLi\Result Object
(
    [connID] => mysqli Object
        (
            [affected_rows] => -1
            [client_info] => 5.6.30
            [client_version] => 50630
            [connect_errno] => 0
            [connect_error] => 
            [errno] => 1146
            [error] => Table 'v3.dr_`dr_admin_menu' doesn't exist
            [error_list] => Array
                (
                    [0] => Array
                        (
                            [errno] => 1146
                            [sqlstate] => 42S02
                            [error] => Table 'v3.dr_`dr_admin_menu' doesn't exist
                        )

                )
@dayrui
Copy link
Author

dayrui commented Jul 6, 2016

"insert" replace "replace"

@dayrui
Copy link
Author

dayrui commented Jul 6, 2016

$this->db->table('admin_menu')->replace([

@sv3tli0
Copy link
Contributor

sv3tli0 commented Jul 6, 2016

It will be good if you use at least for your code the Markdown code tags (new line + ```, before and after the code). There is a URL to Markdown info page, down here left from Comment button ..

@lonnieezell
Copy link
Member

I've edited the comment with the code tags like @sv3tli0 mentioned so it's all readable.

What I'm seeing, though, is the system telling you that Table 'v3.dr_dr_admin_menu' doesn't exist`. I don't know if you have $prefix set in database config file, but that's the only way that I can think of the system changing the table name that you're using. If you figure out that error, I think you'll find that it works as expected.

@dayrui
Copy link
Author

dayrui commented Jul 7, 2016

@lonnieezell
I'm just so excited to find out which.

'database' => 'v3', 'DBPrefix' => 'dr_',
When using delete, insert, there will be an error

$this->db->table('admin_menu')->whereIn('id', $this->ids)->delete()
$this->db->table('admin_menu')->insert($insert)

/system/Database/BaseBuilder.php:

public function delete($where = '', $limit = null, $reset_data = true, $returnSQL = false) { $table = $this->QBFrom[0]; // repair

And:

`public function insert($set = null, $escape = null, $test = false)
{
if ($set !== null)
{
$this->set($set, '', $escape);
}

    if ($this->validateInsert() === false)
    {
        return false;
    }

    $sql = $this->_insert(
        $this->QBFrom[0], // Repair
        array_keys($this->QBSet),
        array_values($this->QBSet)
    );`

@sv3tli0
Copy link
Contributor

sv3tli0 commented Jul 7, 2016

Did you set any value to swapPrefix?
Field "swapPre" into App/Config/Database

@lonnieezell
Copy link
Member

It does look like their might be an issue with some doubly-applied sanitization going on between the constructor and the from method.

Just to verify - what is your table name in the db, dr_admin_menu?

@lonnieezell
Copy link
Member

@dayrui You'll be happy to know it's not your code. But it has unearthed a major bug in the handling of tables with prefixes. Working on that, but might take a touch to get it all working correctly.

@Rost445
Copy link

Rost445 commented Nov 30, 2023

$this->db->table('admin_menu')->replace([

"replace" - Thanks for the advice! This worked for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants