MYSQL FAIL TO CONNECT TO DATATABLE EDITOR

MYSQL FAIL TO CONNECT TO DATATABLE EDITOR

xiiiSaikixiiiSaiki Posts: 5Questions: 3Answers: 0
edited November 2016 in Free community support

hi and thank you for this lovely plugin

i downloaded editor datatable and i wan to run it in my wampserver
so here is what ive done so far :smile:

$sql_details = array(
"type" => "Mysql", // Database type: "Mysql", "Postgres", "Sqlite" or "Sqlserver"
"user" => "root", // Database user name
"pass" => "", // Database password
"host" => "localhost", // Database host
"port" => "80", // Database connection port (can be left empty for default)
"db" => "test", // Database name
"dsn" => "" // PHP DSN extra information. Set as charset=utf8 if you are using MySQL
);
- after that i used this link "https://editor.datatables.net/examples/sql/mysql.sql" to fetch data to my database "test"

but i got this
{"sError":"An error occurred while connecting to the database 'test'. The error reported by the server was: SQLSTATE[HY000] [2006] MySQL server has gone away"}

do i miss something ??

and thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin

    Sounds like your PHP and MySQL connection isn't working. Can you make a standard PDO SELECT request to your database from your PHP?

    Allan

  • xiiiSaikixiiiSaiki Posts: 5Questions: 3Answers: 0
    edited November 2016

    it works fine using a very simple query :
    ----- config.php -----i made this costum config to call a specifc database

    <?php
    
        $db_host = "localhost";
        $db_name = "test";
        $db_user = "root";
        $db_pass = "";
        
        
        try{
            
            $db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
            $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $db_con->exec("set names utf8");
        }
        catch(PDOException $e){
            echo $e->getMessage();
        }
    
    
    
    <?php
    >
    ---------------- end of config.php --------------------
    ?>
    
    
    
    ----------------starting index.php -------------------
    <html>
    <head></head>
    <body>
     <table>
    <?php
    include 'config.php';
    
    $stmt = $db_con->prepare("select * from users");
    $stmt->execute();
     if($stmt->rowCount() > 0){
            
            while($row=$stmt->fetch(PDO::FETCH_ASSOC))
             {
                 extract($row);
                 ?>
                <tr>
                <td><?php echo $id ?></td>
                <td><?php echo $title ?></td>
                <td><?php echo $first_name ?></td>
                <td><?php echo $last_name ?></td>
                <td><?php echo $city ?></td>
                </tr>
    
    <?php
             }
     }
    
    
    <?php
    >
    
    
    ---------------------------------- end of index.php ---------------------------------
     
    result ----------------------------------------------------------------------------------
    ?>
    
    
    1   Miss    Quynn   Contreras   Slidell
    2   Mr  Kaitlin Smith   Orlando
    3   Mrs Cruz    Reynolds    Lynn
    4   Dr  Sophia  Morris  Belleville
    5   Miss    Kamal   Roberson    Rehoboth Beach
    6   Dr  Dustin  Rosa    Jersey City
    7   Dr  Xantha  George  Billings
    8   Mrs Bryar   Long    San Bernardino
    9   Mrs Kuame   Wynn    Truth or Consequences
    10  Ms  Indigo  Brennan Moline
    11  Mrs Avram   Allison Rancho Palos Verdes
    12  Mr  Martha  Burgess Toledo
    13  Miss    Lael    Kim Lake Charles
    14  Dr  Lyle    Lewis   Simi Valley
    15  Miss    Veronica    Marks   Glens Falls
    16  Mrs Wynne   Ruiz    Branson
    17  Ms  Jessica Bryan   Boulder City
    18  Ms  Quinlan Hyde    Sheridan
    19  Miss    Mona    Terry   Juneau
    20  Mrs Medge   Patterson   Texarkana
    21  Mrs Perry   Gamble  Arcadia
    22  Mrs Pandora Armstrong   Glendora
    23  Mr  Pandora Briggs  Oneida
    24  Mrs Maris   Leblanc Cohoes
    25  Mrs Ishmael Crosby  Midwest City
    26  Miss    Quintessa   Pickett North Tonawanda
    27  Miss    Ifeoma  Mays    Parkersburg
    28  Mrs Basia   Harrell Cody
    29  Mrs Hamilton    Blackburn   Delta Junction
    30  Ms  Dexter  Burton  Gainesville
    31  Mrs Quinn   Mccall  Fallon
    32  Mr  Alexa   Wilder  Johnson City
    33  Ms  Rhonda  Harrell Minnetonka
    34  Mrs Jocelyn England Chico
    35  Dr  Vincent Banks   Palo Alto
    36  Mrs Stewart Chan    Grand Forks
    -----------------------------------------------------------------------------------------
    

    but when i use the config of editor datatable in that case he couldn't connect to test database
    :(

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,175Questions: 1Answers: 10,409 Site admin
    Answer ✓

    I suspect this is the issue:

    "port" => "80", // Database connection port (can be left empty for default)

    Are you really running your MySQL server on port 80? 3306 is the default, while 80 is used for HTTP servers.

    Allan

  • xiiiSaikixiiiSaiki Posts: 5Questions: 3Answers: 0

    thanks bro it's working now
    it was the port = 3306 not port = 80 my mistake sorry

This discussion has been closed.