Could someone please check these tables?

Hello

I was given the info below to create 2 tables,

and below this info are the 2 tables I have created,

could someone please check they are correctly coded,

my 1st try at tables creating :slight_smile:


CREATE TABLE ip2nation (
ip int(11) unsigned NOT NULL default ‘0’,
country char(2) NOT NULL default ‘’,
blocked tinyint(4) NOT NULL default ‘0’,
KEY ip (ip)
);

CREATE TABLE ip2nationCountries (
code varchar(4) NOT NULL default ‘’,
country varchar(255) NOT NULL default ‘’,
lat float NOT NULL default ‘0’,
lon float NOT NULL default ‘0’,
blocked tinyint(4) NOT NULL default ‘0’,
PRIMARY KEY (code),
KEY code (code)
);

$db_desc = “Creating <b>ip2nation</b> table”;
$db_query = “CREATE TABLE " . DB_PREFIX . "ip2nation (
ip int(11) unsigned NOT NULL default ‘0’,
country varchar(2) NOT NULL default ‘’,
blocked tinyint(4) NOT NULL default ‘0’,
KEY ip (ip);”;

$db_desc = “Creating <b>ip2nationCountries</b> table”;
$db_query = " CREATE TABLE " . DB_PREFIX . "ip2nationCountries (
code varchar(4) NOT NULL default ‘’,
country varchar(255) NOT NULL default ‘’,
lat float NOT NULL default '0', lon float NOT NULL default ‘0’,
blocked tinyint(4) NOT NULL default ‘0’,
PRIMARY KEY (code),
KEY code (code);";

not sure why you posted this in the (x)html forum – php seems more apprpriate, although you shouldn’t really need to create tables via php, seeing as how you’d only need to do it once and it seems rather wasteful to write a php program to do it when you could simply submit the CREATE statements to mysql directly

if you declare PRIMARY KEY (code), then KEY code (code) is redundant

how are these two tables supposed to be related? how will you be using them?

Hello,

thank you for your reply,

Hmmmm, I was sure I clicked on Database-SQL

I am following the data I was given, it says Primary Key & Key, so that is what I did :slight_smile:

1 will be populated with Country codes, eg: nz, aus, ch

2 will be populated with ip address numbers for the countries,

could you please assist me in getting the Table Creation code correct?

:slight_smile:

what you were given is of dubious quality, eh

yeah, but are the tables supposed to be related?

how were you planning to use them?

Hello r937

yes dubious quality only to your eye, I was working on they know what they are doing…lol

below I have posted the info I was given to create 2 new tables and populate them,

but! I want to create the tables and populate them when I install the script, so I am adding the:

$db_desc = “Creating <b>ip2nation</b> table”;

$db_desc = “Creating <b>ip2nationCountries</b> table”;

to the Install.php in my script.

##########################################################

Open Proxy Country Ban System

(c) 2007

#########################################################

  1. Run the Query on your SQL DB.
  2. Import the enclosed file “SQLDUMP.sql” into your SQL DB.
  3. Make the file edits below.
  4. Upload enclosed file: denial.php into your ADMIN directory.
  5. Upload enclosed file: denial.tpl.php into your admin/templates directory.
  6. Upload your modified files.
  7. In admin, goto the OPCBS Configuration Module and define your preferences.

==============================

RUN THE FOLLOWING SQL QUERIES:

==============================

ALTER TABLE probid_gen_setts
ADD
enable_proxy_deny TINYINT( 4 ) NOT NULL ,
ADD
enable_country_deny TINYINT( 4 ) NOT NULL ;

DROP TABLE IF EXISTS ip2nation;

CREATE TABLE ip2nation (
ip int(11) unsigned NOT NULL default ‘0’,
country char(2) NOT NULL default ‘’,
blocked tinyint(4) NOT NULL default ‘0’,
KEY ip (ip)
);

DROP TABLE IF EXISTS ip2nationCountries;

CREATE TABLE ip2nationCountries (
code varchar(4) NOT NULL default ‘’,
country varchar(255) NOT NULL default ‘’,
lat float NOT NULL default ‘0’,
lon float NOT NULL default ‘0’,
blocked tinyint(4) NOT NULL default ‘0’,
PRIMARY KEY (code),
KEY code (code)
);

====================================================================

IN PHPMYADMIN - Click on IMPORT then browse, and select enclosed file: SQLDUMP.sql and then click on Go. This will populate your IP database.

====================================================================

Some additional info from the sql to populate the databases, 2 examples of each.

INSERT INTO ip2nation (ip, country) VALUES(184549375, ‘us’);
INSERT INTO ip2nation (ip, country) VALUES(3332726783, ‘ca’);

INSERT INTO ip2nationCountries (code, country, lat, lon) VALUES(‘ad’, ‘Andorra’, 42.3, 1.3);
INSERT INTO ip2nationCountries (code, country, lat, lon) VALUES(‘ae’, ‘United Arab Emirates’, 24, 54);

your help appreciated :slight_smile:

you’re welcome

good luck :slight_smile:

Hello r937

wait! :slight_smile:

could you please correct these for me ?

$db_desc = “Creating <b>ip2nation</b> table”;
$db_query = “CREATE TABLE " . DB_PREFIX . "ip2nation (
ip int(11) unsigned NOT NULL default ‘0’,
country varchar(2) NOT NULL default ‘’,
blocked tinyint(4) NOT NULL default ‘0’,
KEY ip (ip);”;

$db_desc = “Creating <b>ip2nationCountries</b> table”;
$db_query = " CREATE TABLE " . DB_PREFIX . "ip2nationCountries (
code varchar(4) NOT NULL default ‘’,
country varchar(255) NOT NULL default ‘’,
lat float NOT NULL default '0', lon float NOT NULL default ‘0’,
blocked tinyint(4) NOT NULL default ‘0’,
PRIMARY KEY (code),
KEY code (code);";

sorry, man, i don’t do php

Hi Ray,

I know that I am jumping into this thread late so I apologize for it, but reinforcing in a big way what r937 indicated this is normally a really, really bad idea to have php constructing tables like this.

I can not think of one good reason (albeit feeling very un-creative currently) why this is needed.

You can write sql scripts that you run that drop and recreate your table structures as well as data. When testing and you have operations that require a ‘fresh’ database it takes only seconds (depending on the size of the data) normally to drop a polluted table and use your sql script to recreate a fresh one. You can initialize these scripts in PHPMyAdmin, MySQL Workbench or from the command line. You can even write your php file to issue the command line creation of these scripts.

I hope you know what you are getting into.

Regards,
Steve

Hi Steve, always good to hear from you, jumping in late or early is always welcome :slight_smile:

yes I understand what you are saying, and would like to learn more about creating a new table then populating it,

my lack of knowledge in that method led me to trying to create the new table when the script Installs,

I thought I could just add one more Creating table command :slight_smile:

At this time I have not succeeded, I get a SQL Error when the Installation process reaches my new table creating command,

All info/advice keenly received :slight_smile:

let me guess what that error message said…

hmm…

nope, sorry, i have no idea

would you mind revealing it?

Hello r937

all is well :slight_smile:

I gave up on the Install method for the 2 databases,

I decided to create the 2 new tables within phpMyAdmin, then populated them,

so far so good, still in the process of completing and checking :slight_smile:

I decided to create the 2 new tables within phpMyAdmin, then populated them,
Good move Ray!

Hi Steve,

yes creating the tables and populated them was quick and easy, But! I had a problem here: