Selecting a database..?

Selecting a database..?

CatCat Posts: 18Questions: 8Answers: 0

Hi,
I'm fairly new to webdevelopment, I have a fair bit of html experience but not so much PHP and AJAX or MySQL implementation

I have an almost-default XAMPP server setup which I've linked to the website I'm developing, and now it's time for me to add a search function to the site. It needs to have server-side processing and foreign keys, so I've created a InnoDB database called testdb in phpMyAdmin and added the datatables_demo table from scripts/mysql.sql to it with all its default content. I have also temporarily removed all the default user passwords in case it would get in the way for this example.

Now, I'm trying to hook up the DataTables examples to datatables_demo in the testdb database, but no matter what I do I always get the error 1046 "No database selected" when I try to use any of the DataTables examples and I can't for the life of me figure out how to "select a database" for it. As far as I can see, DataTables by default seems to look for the data source in server_processing.php, and when I look in there I see it selecting the table datatables_demo (which is why I made the same table in phpMyAdmin) but... it doesn't seem to say where to find the table? If that's the reason for no database being selected, how do I fix that?

Following W3Schools, I tried adding the following line to the top of server_processing.php
$con=mysqli_connect("localhost","root","","testdb");
but it didn't seem to work. I'm not sure what I'm doing wrong and/or what I'm missing, any help will be greatly appreciated

Thanks in advance,
meow

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    Look again at the server_processing.php file. You need to define your connection details:
    // SQL server connection information $sql_details = array( 'user' => '', 'pass' => '', 'db' => '', 'host' => '' );

  • CatCat Posts: 18Questions: 8Answers: 0
    edited August 2014

    Ooohhhhh..!! I see now, thank you so much! And thanks for the quick reply, I didn't expect someone to answer the same day ^^

    I added the information, but unfortunately I still get error 1046 "No database selected"... but now that I've definitely selected a database the way it's supposed to be done, now I'm even more clueless on to why it's not working

    I'm trying everything I can think of to make it work right now, I'll post here if I get it working

    EDIT:
    By the way, here's what I changed the code you mentioned to;
    $sql_details = array(
    'user' => 'root',
    'pass' => '',
    'db' => 'testdb',
    'host' => 'localhost'
    );

  • CatCat Posts: 18Questions: 8Answers: 0

    I got it!! OMG thank you so much tangerine, you may have saved me weeks of headache trying to find it! xD

    I got a different error now, but the 1046 is fixed, thanks a ton! :D

This discussion has been closed.