A
A
Aaron Ramsey2014-03-19 19:51:50
CMS
Aaron Ramsey, 2014-03-19 19:51:50

How to do the following when installing CMS?

Insert text in SQL
This is
/* Create the posts table: */
CREATE TABLE posts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
slug VARCHAR(255),
body TEXT,
created DATETIME DEFAULT NULL,
format VARCHAR(20 ) DEFAULT NULL,
user_id INT
);
/* Insert a publication: */
INSERT INTO posts (title,slug,body,created,format,user_id)
VALUES ('Welcome to academic*', 'welcome_to_academic', "You can edit or delete this publication by creating an administrator account here .", NOW(), 'standard', '1');
/* Create the pages table: */
CREATE TABLE pages (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(50),
slug VARCHAR(255),
body TEXT,
created DATETIME DEFAULT NULL
);
/* Insert two pages: */
INSERT INTO pages (title,slug,body,created)
VALUES ('About', 'about', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a dui metus, vitae auctor dolor. Fusce leo turpis, sagittis sed dignissim id, rhoncus ac diam, Nam suscipit rutrum venenatis, Donec mi urna, pharetra eget cursus ut, interdum in risus.', NOW());
INSERT INTO pages (title,slug,body,created)
VALUES ('Links', 'links', '###Link category
* [Link1](#)
* [Link2](#)
* [Link3](#)' ,NOW());
CREATE TABLE users (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(150),
pseudo VARCHAR(250),
password VARCHAR(50),
role VARCHAR(20),
about TEXT,
created DATETIME DEFAULT NULL
);
/* Create the settings table: */
CREATE TABLE settings (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
slug VARCHAR(255),
value VARCHAR(300)
);
/* Insert settings values: */
INSERT INTO settings (name,value)
VALUES ('Site.name', 'Academic blog');
INSERT INTO settings (name,value)
VALUES ('Site.description', 'The minimalist blog CMS');
INSERT INTO settings (name,value)
VALUES ('Site.email', '[email protected]');
INSERT INTO settings (name,value)
VALUES ('Site.layout', 'academic');
INSERT INTO settings (name,value)
VALUES ('Author.info', 'no');
INSERT INTO settings (name,value)
VALUES ('Google.analytics', 'none');
INSERT INTO settings (name,value)
VALUES ('Disqus.id', 'none');
INSERT INTO settings (name,value)
VALUES ('Gripr.info', 'no');
I open phpMyAdmin
I go to the database - I open SQl - I insert that text there.
Writes to me - SQL query:
/* Create the posts table:
title VARCHAR( 255 ) ,
slug VARCHAR( 255 ) ,
body TEXT,
created DATETIME DEFAULT NULL ,
format VARCHAR( 20 ) DEFAULT NULL ,
user_id INT
);
MySQL answer: Documentation
#1050 - Table 'posts' already exists
I've already deleted all the tables and redid everything - but it still doesn't work(
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nowm, 2014-03-19
@szags

You have written in the server response that the table already exists. You are trying to create a post table, but it already exists. You need to write CREATE TABLE IF NOT EXISTS `posts`
instead of CREATE TABLE posts . Wherever there is a CREATE TABLE, you need to write CREATE TABLE IF NOT EXISTS. This statement specifies that a new table should not be created if it already exists.
The trick with imports is that when you get an error, the script execution stops. If you have CREATE TABLE `posts` followed by INSERT INTO `posts`, then there will be no INSERT execution, because an error occurred at the time of CREATE TABLE and the script stops immediately. Additional "IF NOT EXISTS" directives ensure that the table creation step is simply skipped if one already exists. It will just be skipped - without interrupting the script.

Z
zxmd, 2014-03-19
@zxmd

For a start it is necessary probably to create/pass in a DB.
use DB_NAME;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question