Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2013
    Posts
    3

    Unanswered: How to create Postgresql database using in PHP code

    Hi,

    i was use the code below

    $test = `createdb -U sql-ledger $db 2>&1`;

    sql-ledger is username of phppgadmin

    but i can get the error

    "Password: createdb: could not connect to database postgres: fe_sendauth: no password supplied"

    how to pass the password?

    please any one know the solution give me the replay

  2. #2
    Join Date
    Dec 2012
    Posts
    43
    Quote Originally Posted by Ravikumar R View Post
    Hi,

    i was use the code below

    $test = `createdb -U sql-ledger $db 2>&1`;

    sql-ledger is username of phppgadmin

    but i can get the error

    "Password: createdb: could not connect to database postgres: fe_sendauth: no password supplied"

    how to pass the password?

    please any one know the solution give me the replay
    "sql-ledger" is not the username of phppgadmin. It's probably a username of a PostreSQL-Server.

    In "createdb" there is no option for the password. You can use a .pgpass file in the HOME directory of the calling user. Please refer the documentation.

    Otherwise you can execute a "CREATE DATABASE" - statement with phppgadmin or with a php-script or directly as command "createdb" or as an SQL-statement in very much program languages like Perl, Python etc.

    If you tell us more of your project we will give you more hints. But we don't want to guess a lot:
    For example:
    - Do you have direct access to the PostgreSQL-Server (Is the server running on your computer at home)?
    - What operating system do you use?
    - Do you have some skills with the command line?
    - Did you develop some PHP-scripts or any other programs in any other programming languages (and what languages)?
    etc.

  3. #3
    Join Date
    Jun 2013
    Posts
    3
    Hi bibjet thanks for ur replay, and sorry for my english

    sql-ledger is i'm creating the username in phppgadmin database,

    my project is, i add one user from sugarcrm to my project then the user also created in to sql-ledger project so that time create the database, conf file and template through the php code my above code it's running successfully on postgresql 8.1 version but now i'm using 9.1 version,

    i'm using Ubuntu 12.04 os,

    i know some one skills only in command line,

  4. #4
    Join Date
    Dec 2012
    Posts
    43
    Hello

    Please note that the following code isn't php:
    `createdb -U sql-ledger $db 2>&1`;

    Due to the backticks >`< the command will be executed external to PHP.

    So you can create the database immediately with this command instead using PHP in a telnet console:
    createdb -U sql-ledger my_new_database

    Of course you have to replace >my_new_database< with the real name of the database.

    The external program >createdb< will prompt you for the password of >sql-ledger<


    Are you sure that there is a user called >sql-ledger< created on your PostgreSQL server?

    If your operating system is installed recently the only PostgreSQL user is >postgres<.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •