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

[feature] can you support postgresql? #411

Open
zhangmazi opened this issue Dec 8, 2023 · 0 comments
Open

[feature] can you support postgresql? #411

zhangmazi opened this issue Dec 8, 2023 · 0 comments

Comments

@zhangmazi
Copy link

zhangmazi commented Dec 8, 2023

i have try change codes to install on postgresql, but the result have some errors.

eg.

  1. pq, insert PK(id) issue. (artisan lavalite:install)

codes
file: vendor/lavalite/framework/src/Litepie/Install/Installers/Scripts/ConfigureDatabase.php

`
public function fire(Command $command)
{
$this->command = $command;

    $connected = false;

    // while (!$connected) {
        // $host = $this->askDatabaseHost();
        // $username = $this->askDatabaseUsername();
        // $password = $this->askDatabasePassword();
        // $database = $this->askDatabaseName();

        $host = '127.0.0.1';
        $port = '5432';
        $username = 'user_dev';
        $password = '6666666';
        $database = 'lavalite_cms';

        if ($this->databaseConnectionIsValid($host, $port, $username, $password, $database)) {
            config(['database.connections.pgsql.host' => $host]);
            config(['database.connections.pgsql.port' => $port]);
            config(['database.connections.pgsql.username' => $username]);
            config(['database.connections.pgsql.password' => $password]);
            config(['database.connections.pgsql.database' => $database]);
            $connected = true;
        } else {
            $command->error('Please ensure your database credentials are valid.');
        }
     }
    if ($connected) {
        $this->env->write($database, $username, $password, $host);
        $command->info('Database successfully configured.');
    }

}


protected function databaseConnectionIsValid($host, $port, $username, $password, $database)
{
    try {
        // $link = @mysqli_connect($host, $username, $password, $database);
        $pgConnectionString = sprintf('host=%s port=%d dbname=%s user=%s password=%s', $host, $port, $username, $password, $database);
        var_dump($pgConnectionString);
        $link = @pg_connect($pgConnectionString);

        if (!$link) {
            return false;
        }

        return true;
    } catch (Exception $e) {
        return false;
    }
}

}

`

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

1 participant