(1046 No database selected )

(1046 No database selected )

zezooooozezooooo Posts: 12Questions: 1Answers: 0

i cann't connect to database and (I work with mysql only)

This question has accepted answers - jump to:

Answers

  • zezooooozezooooo Posts: 12Questions: 1Answers: 0
    edited December 2018
    <?php
     
    // DataTables PHP library
    include( "DataTables.php" );
     
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
     
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'fac_sys' )
        ->fields(
            Field::inst( 'std_name' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A first name is required' ) 
                ) ),
            Field::inst( 'std_code' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A code is required' )  
                ) ),
            Field::inst( 'password' ),
            Field::inst( 'email' )
                ->validator( Validate::email( ValidateOptions::inst()
                    ->message( 'Please enter an e-mail address' )   
                ) ),
            
            Field::inst( 'enroll_date' )
                ->validator( Validate::numeric() )
                ->setFormatter( Format::ifEmpty(null) ),
            Field::inst( 'enroll_date' )
                ->validator( Validate::numeric() )
                ->setFormatter( Format::ifEmpty(null) ),
            Field::inst( 'birth_date' )
                ->validator( Validate::dateFormat( 'Y-m-d' ) )
                ->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
                ->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
        )
        ->process( $_POST )
        ->json();
    
  • zezooooozezooooo Posts: 12Questions: 1Answers: 0

    I need help as quick as possible

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @zezooooo ,

    Have you defined the database properties in the your config.php file? See this page here, it talks over that. Also, this thread may also help,

    Cheers,

    Colin

  • zezooooozezooooo Posts: 12Questions: 1Answers: 0

    thank you for repling
    but it gives my errro (An SQL error occurred: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'fac_sys.fac_sys' doesn't exist","data":[],"ipOpts":[],"cancelled":[])
    and the config.php file is

    <?php if (!defined('DATATABLES')) exit(); // Ensure being used in DataTables env.

    // Enable error reporting for debugging (remove for production)
    error_reporting(E_ALL);
    ini_set('display_errors', '1');

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Database user / pass
    */
    $sql_details = array(
    "type" => "Mysql", // Database type: "Mysql", "Postgres", "Sqlserver", "Sqlite" or "Oracle"
    "user" => "root", // Database user name
    "pass" => "", // Database password
    "host" => "localhost", // Database host
    "port" => "", // Database connection port (can be left empty for default)
    "db" => "fac_sys", // Database name
    "dsn" => "charset=utf8mb4", // PHP DSN extra information. Set as charset=utf8mb4 if you are using MySQL
    "pdoAttr" => array() // PHP PDO attributes array. See the PHP documentation for all options
    );

    // This is included for the development and deploy environment used on the DataTables
    // server. You can delete this block - it just includes my own user/pass without making
    // them public!
    if ( is_file($_SERVER['DOCUMENT_ROOT']."/datatables/pdo.php") ) {
    include( $_SERVER['DOCUMENT_ROOT']."/datatables/pdo.php" );
    }
    // /End development include

  • zezooooozezooooo Posts: 12Questions: 1Answers: 0
    edited December 2018

    the alert error is (1146 Table 'fac_sys.datatables_demo' doesn't exist)
    how can i fix that
    sorry it's the first time for using datatable
    it's so awesome
    and your support is excellent.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited December 2018 Answer ✓

    Hi @zezooooo ,

    datatables_demo is one of the example tables - in the first link I posted above, where you configure the database connection properties, there's a section called "Examples SQL". The SQL needed to create the sample tables for each database platform is in that section.

    It does seem like you've skipped a few steps. I would strongly suggest going back and ensuring each of the those steps have been completed - i.e. you need a database, with data, and notified Editor what the connection properties are, webserver installed, etc., before you can use it.

    fac_sys.fac_sys isn't one of ours, so I suspect it's your PHP script asking for it.

    Cheers,

    Colin

  • zezooooozezooooo Posts: 12Questions: 1Answers: 0

    Hi @colin
    my database has data and word in another files
    my problem is in edit the example bootstrap 3
    and the connection to my database(fac_sys)
    I want to know what scripts should i edit

  • zezooooozezooooo Posts: 12Questions: 1Answers: 0

    I want to reply at 11 am to can modify the error
    thanks

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Your connection properties look unusual:

    "user" => "root", // Database user name
    "pass" => "", // Database password
    

    I wouldn't expect that - normally you have a database user. Can you attach to the DB with the command-line mysql program with those login credentials?

  • zezooooozezooooo Posts: 12Questions: 1Answers: 0
    edited December 2018

    not this .
    my database username is root
    and without password
    and the file connected with table (datatable_demo)
    and i edited it to (students) in my server script
    i work on bootstrap 3 example
    https://editor.datatables.net/examples/styling/bootstrap.html

  • zezooooozezooooo Posts: 12Questions: 1Answers: 0

    I wait too much

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    Let's circle around to make sure I understand. You want to run the Editor Bootstrap 3 demo in a database called fac_sys? You have imported our demo SQL file, and renamed datatable_demo to be students? Have you also edited the PHP file with the Editor PHP code to match that, as I don't see students mentioned anywhere else above.

    I'm a little confused I'm afraid, so if you could clarify these points, that would be great.

    Allan

This discussion has been closed.