473,379 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Build_DB PHP script

Hello Everybody !!!

How do you put the folowing code into a php script that will create the
database and then the Tables ?
I tried doing
$sql = '
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `gamoto`;
USE `gamoto`;
';
$result = mysql_query($sql) or die(mysql_error());

But i get errors when I execute the query....

I know the long way of doing it..... (query by query, table by table)
I need a quicker way.... Thanks guys !!!!
************************************************** ***********************
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `gamoto`;
USE `gamoto`;

DROP TABLE IF EXISTS `cms_access_levels`;
CREATE TABLE `cms_access_levels` (
`access_lvl` int(10) unsigned NOT NULL auto_increment,
`access_lvl_name` varchar(45) NOT NULL default '',
PRIMARY KEY (`access_lvl`,`access_lvl_name`)
) TYPE=MyISAM;

/*!40000 ALTER TABLE `cms_access_levels` DISABLE KEYS */;
INSERT INTO `cms_access_levels` VALUES (1,'user'),
(2,'moderator'),
(3,'admin');
/*!40000 ALTER TABLE `cms_access_levels` ENABLE KEYS */;

DROP TABLE IF EXISTS `cms_users`;
CREATE TABLE `cms_users` (
`cms_user_id` int(10) unsigned NOT NULL auto_increment,
`cms_user_email` varchar(60) NOT NULL default '',
`cms_user_passwd` varchar(50) NOT NULL default '',
`cms_user_name` varchar(45) NOT NULL default '',
`cms_user_surname` varchar(45) NOT NULL default '',
`cms_user_access_lvl` tinyint(4) unsigned NOT NULL default '1',
`cms_customer_id` int(10) unsigned NOT NULL default '0',
PRIMARY KEY
(`cms_user_id`,`cms_user_email`,`cms_user_access_l vl`,`cms_customer_id`)
) TYPE=MyISAM;
************************************************** *************************************

Thanks Again
Angelos..

P.S. Gamoto !
Jul 17 '05 #1
6 1449
> Hello Everybody !!!

How do you put the folowing code into a php script that will create the
database and then the Tables ?
I tried doing
$sql = '
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `gamoto`;
USE `gamoto`;
Isn't it

USE gamoto;

?
Thanks Again
Angelos..

P.S. Gamoto !


Simon
Jul 17 '05 #2
> Isn't it

USE gamoto;

?


I don't think that what i had was wrong ...
And also I am asking how you would do that .. The whole script !
Thanks Simon ;-)
Jul 17 '05 #3
>> Isn't it

USE gamoto;

?


I don't think that what i had was wrong ...
And also I am asking how you would do that .. The whole script !
Thanks Simon ;-)


Yes, but the problem is where in the script is your problem?
Have you tried line by line toi find out where it is wrong?

If you show use the error been returned we might be able to help more.

On my system, (phpMyAdmin), the script works fine.

But running it in a php script it does not because of the quotes, "`".

CREATE DATABASE `gamoto` ... is not the same as
CREATE DATABASE 'gamoto'

in the script it should be

CREATE DATABASE gamoto

and
USE gamoto.

Simon
Jul 17 '05 #4
CREATE DATABASE `gamoto` ... is not the same as
CREATE DATABASE 'gamoto'

in the script it should be

CREATE DATABASE gamoto

and
USE gamoto.


Ahhhhh ... I see...
So that's my problem... I thought that I can have this ` ` quotes in the
script.
Because the SQL code I am trying to run through php is an export from
phpmyadmin or a Buckup from MySQL Admin....

So I though it should work as it is if you run it correclty...
But still if PHPmyadmin runs the code... it meens that I can run it some how
.... :S

Strange... thanks anyway...
Until I get an answer I am going to remove this ` ` quotes ;)
Thanks
Jul 17 '05 #5
> CREATE DATABASE `gamoto` ... is not the same as
CREATE DATABASE 'gamoto'

in the script it should be

CREATE DATABASE gamoto

and
USE gamoto.


Ahhhhh ... I see...
So that's my problem... I thought that I can have this ` ` quotes in the
script.
Because the SQL code I am trying to run through php is an export from
phpmyadmin or a Buckup from MySQL Admin....

So I though it should work as it is if you run it correclty...
But still if PHPmyadmin runs the code... it meens that I can run it some
how ... :S

Strange... thanks anyway...
Until I get an answer I am going to remove this ` ` quotes ;)
Thanks


I don't know the answer myself, it is either an error in the way phpMyAdmin
displays the SQL or the actual character been used in their query.
But I know that only CREATE and USE cannot have quotes (" and '), all the
others should work just fine.

Simon
Jul 17 '05 #6
That is another piece of code :
************************************************
<?
ini_set('error_reporting', E_ALL);
ini_set("display_errors","1"); ?>
<?
require_once ('../../Connections/willans.php');

$create = 'CREATE DATABASE IF NOT EXISTS gamoto';
$results = mysql_query($create) or die (mysql_error());
mysql_select_db("gamoto");

$sql = '
DROP TABLE IF EXISTS cms_access_levels ;
CREATE TABLE IF NOT EXISTS cms_access_levels (
access_lvl int(10) unsigned NOT NULL auto_increment,
access_lvl_name varchar(45) NOT NULL ,
PRIMARY KEY ( access_lvl , access_lvl_name )
) TYPE=MyISAM;
';
$results = mysql_query($sql) or die (mysql_error());
if ($results)
echo "DB Created";
?>
************************************************** ****

And that is the Error :

##############################
You have an error in your SQL syntax. Check the manual that corresponds to
your MySQL server version for the right syntax to use near '; CREATE TABLE
IF NOT EXISTS cms_access_levels ( access_lv
##############################
For some reason it doesn't display the whole error ... but anyway that is
not the problem.

How am I going to make the $sql RUN ???
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sticks | last post by:
ok... im not quite sure how to describe my problem. i have a php script that runs through my entire php site and writes the resulting output to html files. this is necessary as the nature of the...
6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
2
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
3
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.