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

Using rawQuery for CREATE TABLE #1003

Open
boionfire81 opened this issue Nov 21, 2022 · 2 comments
Open

Using rawQuery for CREATE TABLE #1003

boionfire81 opened this issue Nov 21, 2022 · 2 comments

Comments

@boionfire81
Copy link

Doesn't seem to work. It says error, but when using getLastErrno() it prints nothing

@boionfire81
Copy link
Author

Here's my code
`echo "start";

    require_once('includes/db/MysqliDb.php');

    echo "<br>Included database driver<br>";

    echo $_POST['host']."<br>".$_POST['username']."<br>".$_POST['password']."<br>".$_POST['name']."<br>".$_POST['key'];
    $db = new MysqliDb (Array (
            'host' => $_POST['host'],
            'username' => $_POST['username'], 
            'password' => $_POST['password'],
            'db'=> $_POST['name']));
            
    if($db->rawQuery("CREATE TABLE `settings`(`setting_id` varchar(100) COLLATE utf8mb4_bin DEFAULT NULL,`setting_value` varchar(1000) COLLATE utf8mb4_bin DEFAULT NULL")){
        
        echo "success";
        
    }else{
        
        $error=$db->getLastError();
        echo $error;
        exit;
        
    }`

It echos my stuff. I verified the login was correct a couple times, and nothing prints up as to why the raw query doesn't work

@darkcavalry
Copy link

Im using this query for table creation maybe it's help for you.

         $db_pref = '';
        // * users Table
        if(!$db->tableExists($db_pref."users")){
            $db->rawQuery("
                            CREATE TABLE `".$db_pref."users` (
                            `user_id` int(11) NOT NULL AUTO_INCREMENT,
                            `user` varchar(100) DEFAULT NULL,
                            `email` varchar(100) NOT NULL,
                            `password` varchar(50) NOT NULL,
                            `user_type` tinyint(2) NOT NULL DEFAULT 0,
                            `user_active` tinyint(2) NOT NULL DEFAULT 0,
                            `user_primary` tinyint(2) NOT NULL DEFAULT 0,
                            `created_on` timestamp NOT NULL DEFAULT current_timestamp(),
                            `last_login` datetime DEFAULT NULL,
                            `login_ip` varchar(15) DEFAULT NULL,
                            `user_access` text DEFAULT NULL,
                            `user_folder` varchar(20) DEFAULT NULL,
                            `session_token` varchar(255) DEFAULT NULL,
                            `user_theme` varchar(50) DEFAULT NULL,
                            `api_key` varchar(50) DEFAULT NULL,
                            PRIMARY KEY (`user_id`)
                            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPRESSED;
            ");
            if($db->getLastErrno() !== 0){
                die('Table creation error<br>'.$db->getLastError());
            }
        }

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

2 participants