02.02.2014, 13:09
(
Последний раз редактировалось PowerPC603; 02.02.2014 в 13:52.
)
Ok, I got it.
But I want my script to automatically create the database if it doesn't exist.
Something like this.
In this case, the connectionhandle is 1, as you guys explained, but the connection to the database isn't established as the database doesn't exist.
Therefore, the query fails to execute.
But I noticed using Navicat that there are some default databases in my mysql-server package:
- information_schema
- mysql
- performance_schema
If I connect to database "mysql" first, the connection is successful and the query to create the database works fine.
My question:
Can I assume EVERY mysql-server holds these default databases?
If so, I could first connect to database "mysql", create my database if it doesn't exist, close the connection, then open a new connection to my newly created database and populate it with the required tables.
Or is there another way to connect to mysql when there are no databases at all?
I tried using "" as database name but that failed as well.
EDIT:
After investigating a little further (clearing the logs from my mysql package and starting up Navicat, also using ****** search), it seems database "information_schema" should always exist.
Navicat seems to use that database to be able to show all other databases, as there are SELECT queries in the log which refer to "information_schema".
Then perhaps I could use that database to:
- setup my first connection to "information_schema" database
- check if there are no errors, and if there are, shutdown the server (user may be wrong or MySQL isn't installed or whatever)
- create my database "ppctrucking"
- close the connection
- setup a new connection to the new database "ppctrucking"
- populate the new database with the required tables
- insert default data into those new tables
But I want my script to automatically create the database if it doesn't exist.
pawn Код:
SQL_db = mysql_connect(mysql_host, mysql_user, "ppctrucking", mysql_password);
mysql_query(SQL_db, "CREATE DATABASE IF NOT EXISTS `ppctrucking`");
In this case, the connectionhandle is 1, as you guys explained, but the connection to the database isn't established as the database doesn't exist.
Therefore, the query fails to execute.
But I noticed using Navicat that there are some default databases in my mysql-server package:
- information_schema
- mysql
- performance_schema
If I connect to database "mysql" first, the connection is successful and the query to create the database works fine.
My question:
Can I assume EVERY mysql-server holds these default databases?
If so, I could first connect to database "mysql", create my database if it doesn't exist, close the connection, then open a new connection to my newly created database and populate it with the required tables.
Or is there another way to connect to mysql when there are no databases at all?
I tried using "" as database name but that failed as well.
EDIT:
After investigating a little further (clearing the logs from my mysql package and starting up Navicat, also using ****** search), it seems database "information_schema" should always exist.
Navicat seems to use that database to be able to show all other databases, as there are SELECT queries in the log which refer to "information_schema".
Then perhaps I could use that database to:
- setup my first connection to "information_schema" database
- check if there are no errors, and if there are, shutdown the server (user may be wrong or MySQL isn't installed or whatever)
- create my database "ppctrucking"
- close the connection
- setup a new connection to the new database "ppctrucking"
- populate the new database with the required tables
- insert default data into those new tables