一个MySQL数据库和多个表

How to connect to a certain table in MySQL database?

I have tried :

mysql_select_db("baybeestore",$connection);

but it gives me an error :-

"Error : Table 'baybeestore.form' doesn't exist"

But I've created a table named as order. Are there any PHP codes to connect to my table order in the same database that have multiple databases?

Is it wise enough to create multiple database & one table for one website or multiple table with one database?

FULL CODE :

$connection = mysql_connect("localhost","user","1234");
    if(!$connection)
    {
        die('Failed to connect to MySQL :' . mysql_error());
    }
    mysql_select_db("baybeestore",$connection)
    $sql = "INSERT INTO
    form(name, address, email, handphone, item, payment)

    VALUES
    ('$strname', '$straddress', '$stremail', '$strhandphone', '$stritem', '$strpayment')";

    if(!mysql_query($sql, $connection))
    {
        die('Error : ' . mysql_error());
    }
    echo "Data have been saved.";
    mysql_close($connection);

As per your edit/added code. Your originally posted code

You're using two different tables for your queries. Result: ERROR

You have SELECT * FROM order and INSERT INTO form 2 different animals altogether.

If anything, that should be INSERT INTO order or SELECT * FROM form yet... ORDER is a reserved word and should be enclosed with backticks.

I.e.:

INSERT INTO `order`

Maybe you are confusing things. You are supposed to connect to a database and then run queries against one or multiple tables in that database.

So if you have database My_Database and tables table1, table2 you could run

mysqli_select_db($connection, "My_Database");

and then run queries like

$result = mysqli_query("SELECT * FROM table1 WHERE 1 LIMIT 1");

please note that I have changed the function names to mysqli_* because mysql_* functions are deprecated and should not be used anymore

This is a very confusing question. mysql_select_db("baybeestore",$connection); has nothing to do with table names, so your error must be coming from somewhere else. Also, the error refers to the table form, but you say you have created a table named order.

To answer your questions:

  1. You don't connect to tables; you connect to databases and run queries against tables. Connect to my_database or whatever, then run queries like SELECT * FROM my_table.

  2. One database, multiple tables -- definitely not multiple databases, which is much more complicated, generates a ton of overhead, and doesn't help in any way.

Now that you are learning, I recommend you to start learning the correct way. Don't use mysql_ functions. Try learning PDO. Also, use one database per application.

To connect you can try:

    try {
    $conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

You can learn more about PDO through this link