0

I asked similar question before and got some nice code, but i'm concerned with one of comments. I asked how to create and import mysql database from sql file in php on shared hosts. One of commenters said that some hosts might not allow me to do so from php. After digging a bit on other places someone suggested that I could create database from hosts control panel but import it by creating tables via php script executing sql queries this way:

         mysql_query("CREATE TABLE `TABLE NAME HERE` (
        `id` int(25) NOT NULL default '0',
        `CLMN NAME HERE` varchar(250) collate latin1_general_ci default NULL,
        `CLMN NAME HERE` int(10) default NULL,
        PRIMARY KEY  (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;");

        mysql_query("INSERT INTO `TABLE NAME HERE` VALUES ('VALUE HERE', 'VALUE HERE', 'VALUE HERE');"); 

Could anyone comment on that? How do I achieve what i'm trying to do if given host will have restrictions on what i can do with databases in php?

(I'm not sure if creating new question for that is appropriate, but i thought that since previous question have good examples of doing it if host isn't blocking everything i'll create separate question for doing the same if host is more restrictive.)

2 Answers 2

1

shared hosts and frequently do not allow you to create databases, except using their control panel. this is not uncommon, and it's done for good reasons.

and if you can't do it from phpmyadmin or any other administration tool other than their control panel, you won't be able to do it in PHP either.

your only solution in that case is to create the database first using the host's control panel, then edit your backup file and comment out the CREATE DATABASE statement before executing it.

Sign up to request clarification or add additional context in comments.

Comments

0

I would be suprised if a host did not allow you to execute CREATE TABLE statements from PHP code.

What was most likely referred was a block on CREATE DATABASE statements. Typically you will have been assigned a database name already, so you would never execute a CREATE DATABASE statement on a shared host.

1 Comment

Really? What about multiple database hosts? I also seen one that allowed only one database but it wasn't created automatically from my username, I had to create it manually in control panel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.