Can I create my own database with PHP?

I have a PHP server running. Now I want to use databases (MySQL or something similar). Is it possible to create a database from PHP?

I would like to emphasize that in my case I do not have a username and password that I can use to connect to the MySQL server. I also do not have a control panel where I could create a database or table in an existing database.

ADDED:

I think SQLite is what I need. But if I try to create a new database with PHP, I see that PHP is trying to create a file in a directory that is different from the directory where my files should be. He then reports that he cannot create the database, and I think that is because it is trying to create in a directory to which I do not have permission to write. Can I force PHP to create SQLite in a specific directory?

+6
database php mysql
source share
6 answers

I assume that you want to create an SQL database without access to a standalone database server. You can use SQLite , which is a library that creates a lightweight database in a single file without separate processes.

It is not as efficient as a standalone database server, so if you need performance, use the appropriate database server. This is not an unreasonable requirement for a high-performance web application.

+10
source share

Mysql, no. SqlLite is an opportunity, you only need write permissions on the file system. www.sqlite.org/

+4
source share

I would like to emphasize that in my I do not have any username and password to which I can connect to the MySQL server. I also do not have a control panel where I could create databases or tables in an existing database.

This question confuses me because if you are using MySQL, you should be able to create a database with a username and password to connect using your command line administration tool. It is also a way to create a database or table.

Are you saying that you do not have access to the admin tool? You do not have an account? If so, you need to ask them from a person who has such access.

+1
source share

The option is to configure the SQLite database in a directory outside your htdocs folder. This means that people cannot enter the database file name and load the entire database, seriously compromising security.

If you are so addicted, you can even create an abstraction layer between PHP and the DBMS using PDO . Then, to create the database object, you must specify a SQLite specific DSN , write something like this:

$pdo_obj = new PDO('sqlite:/path/to/my_database.sqlite3'); 

and then query it like a regular PDO using PDO functions.

This method will make it easier to simplify the transition to using a client-server DBMS as soon as you can get one setting; it's just a matter of copying the table structure and data into a new database and changing the DSN to something suitable .

+1
source share

It is possible to create a database through PHP, but for this you need to connect to a database that requires a username / password or some kind of authentication. If your database does not allow anonymous logins or something like that, this is not possible.

-one
source share

Yes, just run the sql query to create the database from PHP http://dev.mysql.com/doc/refman/5.0/en/create-database.html

-4
source share

All Articles