Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Create Mysql Database?


How do I make PHP create a database for mysql please?

I can see how to make tables and I have read all the documents
I can find but I don't understand how to make the database itself.

All the tutorials I can find seem to bypass the issue by ignoring it?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Cannot Create Mysql Database And Tables From Php Script
'm trying to build a php script that will build a database in MySQL, create tables, and then populate those tables.

1. I'm not sure how I need to execute the php, from the browser or from the command line?

2. I'm not sure what is wrong with my code, but when I use php -v createdatabase.php, I get output that says my php function to create the database is incorrect. I've looked at other examples on google, and they seem to be almost the same...? Here is the code, I've gone thru it, but I still don't see where I'm making the error: Code:

Create Database
I have basically an install script that creates a database and all the tables and fields.
This works great on the local IIS I have on this machine, but that's because I have 1 password for all databases. THe database cannot be created when I run this on the server that hosts my websites (which is a remote server that I rent space on, it's not in my control).

I'm trying to figure out if what I want to do is possible. I want to have a script that creates a database on any server via a web page.

Create Value On The Fly, Or Store If SQL Database?
I have a value in a database of a car sale which could be $1,000.00 then I have another value in a database of a number of payments, then I create *on the fly* a value of amount per month. Should I store that in the database, or keep that *on the fly*..

What I mean by on the fly is. PHP Code:

Create A Survey By Using Database.
I want to create a survey by using data from database. And then i want display the result by clicking 'View Result'. How could i do that?

Unable To Create A Database
I am unable to create a table in SQL using PHP. I think it might jsut be a code, because it won't even show the page. It just gives me an internal error.

<?php

$connection = @mysql_connect("localhost","jcruz","abc2000")
or die(mysql_error());
$new_db = "testDB2";

$result = @mysql_create_db($new_db, $connection) or die(mysql_error());

?>

Create Array From 2 Database Fields
I want to create an array of product prices, with the product id as the index and the product price as the value, so i can place the prices for particular products wherever i want on my page.

Both product id and price are taken from the Products table
SELECT prod_id, prod_price FROM Products

Due to the client wanting an unusual layout, I cant just loop a table with the data, I need to be able to print $Price[2]; (for product id 2) wherever I like, for example.

Re:which Tool To Use To Create Form For A Database?how To Bu
You may want to check Achievo ATK (http://www.achievo.org/atk). It's a
framework for building data management applications with minimal
coding.

Create Rollover Buttons From Database
I've just finished an online php course and now fighting with a site I'm trying to create (of course  ) I am trying to create a table with rollover buttons. The buttons details are sitting in a table, but everything I try doesn't work. Here are some things I tried: Code:

Create Checkboxes From Database Data
I'm trying to create checkboxes from a database table header row and then pass that to another page.

The checkboxes are gotten from the "header" row of the mysql table.
I check which of these checkboxes are selected and if it is selected, I display the data for the rest of the rows under that same column which is selected as a checkbox. Here's the code to generate the checkboxes:

Help? How To Create Next Buttons When Using A Flat Text Database
Ok, I know the code below does not work but I am wondering about the logic...

1 How do I just print 10 rows.
2 How do I get the buttons.

You get the Idea. Anyway, I would like to know if anyone has done this with text files. I always see mysql as examples but nothing using a flat text database.

<?
$maxResults = 10;
$datafile = "sometextfile.txt";

$rows = @file($datafile);
for($size=0;$size<count($rows);$size++) {
$rows[$size] = chop($rows[$size]);
$coll = split("|",$rows[$size]);


// print something

}
if ($size > 0) {
$currPage = $size / $maxResults;
if ($currPage > 1)
print("<A HREF="test.php" >['prev']</A>");
for ($i = 0; $i < $size / $maxResults; $i++) {
if ($currPage == $i + 1)
printf("<A HREF="test.php"> </A> ",$i + 1);
else
printf("<A HREF="test.php"> </A> ",$i + 1);
}
if ($currPage < size / $maxResults)
print("<A HREF="test.php">['next']</A>);
}
?>

MYSQLDUMP, Create New Database, Before Restoring SQL Data.
I can use mysqldump to create a .sql file backup of my data.

For importing how can I test to see if the DB exists, if it does
import the .sql

If not create the DB then import the .sql!

Looping Database Values To Create An Array
I have a fairly simple php code problem I think, I want to loop values from a mysql database within an array to fill the array. I'v never done this before so your help would be valued if someone had the time.

*denotes where I want to use database values*

How Can I Create A Random 'Phrase' Generator Without Using A Database In PHP3???
I would like to set up a rotating, random phrase generator online. I hav a list of phrases and would like them to pop up randomly as the page is loaded or reloaded...

I've played aroud with random number generators...but how would I get phrases to show up rather than numbers?

Which Tool To Use To Create Form For A Database? How To Build A Interfaces (or Web Pages) In Easy Way?
how to build a interfaces (or web pages) in easy way? how to build a form in easy way? how to automate and create web pages with a tool? which tool to use to create form for a database? I mean there is a way or a tool which help me to build an interfaces (web pages) to deal with the data in a database?

Create A Sequence In MySQL, With Mysql Variable?
This might be fairly easy to do and I think I've seen the code before,
but I haven't seen many good examples of this. Of course Pear::DB
probably uses this code in some of its API, probably in dealing with
auto-increment indexes and prepared statements.

Maybe I'm off base here, but I'm looking for something like this:
(psuedo-code)
Of course the seq table only needs 1 row holding id, which is
updated.
select id from tbl;
// get result resouce and do fetch, store value in $myid
set @myvar = $myid + 1; // can php send to MySQL with a query? (
never seen this )
update myseq set id=@myvar // send this statement through in a
update/query

// for use in PHP code
$newSeqVal = $myid +1

Create A Sequence In MySQL, With Mysql Variable?
This might be fairly easy to do and I think I've seen the code before,
but I haven't seen many good examples of this. Of course Pear::DB
probably uses this code in some of its API, probably in dealing with
auto-increment indexes and prepared statements.

Maybe I'm off base here, but I'm looking for something like this:
(psuedo-code)
Of course the seq table only needs 1 row holding id, which is
updated.
select id from tbl;
// get result resouce and do fetch, store value in $myid
set @myvar = $myid + 1; // can php send to MySQL with a query? (
never seen this )
update myseq set id=@myvar // send this statement through in a
update/query

// for use in PHP code
$newSeqVal = $myid +1

What Is Indexing In Mysql And How It Will Be Useful And How We Can Retrieve Database Content Easily From A Database Table Containing About 5lakhs Datas
I need to select data from a database table containing huge amount of
data. Now I am storing data using one primary key and I am just using
simple select statement, and this process gives me the output but it is
taking long to execute the query. As much I had heared I want to use
some indexing or cluster indexing which might help me but I am not so
familiar with these things.

How To Create A MySQL Table With PHP?
How to create a MySQL table with PHP?

MySQL Table Create
Here is the code I'm trying to create the database with (I'm using phpMyAdmin so I just select the file I want to use and press submit and it creates the tables).

CREATE TABLE bips (
banned_ip varchar(15) NOT NULL);

CREATE TABLE messages (
entry_id double(16,4) DEFAULT &#390;.0000' NOT NULL auto_increment,
name varchar(25) NOT NULL,
email varchar(35) NOT NULL,
icq int(11) NOT NULL,
http varchar(50) NOT NULL,
message mediumtext NOT NULL,
when int(12) NOT NULL,
ip varchar(15) NOT NULL,
UNIQUE entry_id (entry_id),
PRIMARY KEY (entry_id));

------------------------
phpMyAdmin gives me an error with that, (none of those tables exists btw)... the error is

MySQL said: You have an error in your SQL syntax near 'when int(12) NOT NULL, ip varchar(15) NOT NULL, UNIQUE entry_id (entry_i' at line 8 .

Create Mysql Table
I'm trying to create a mysql table in php. i have no problems doing a select, insert or anything else. i just don't know what the proper code is to create a table if it even exists.

Create And Fill-in Form From MySQL
I am working on an admin page where a user can input data into two text fields. When the the form is actioned the two fields are inserted into a table as a row.

What I want to do is when the user calls up the form, any rows that exsist in the table are inserted into the text fields. So the user will see x number of rows with the text fields on the form (x number being number of rows in table). The data is listed in order as determined by the MySQL query. At the end I want to add two blank text fields.

The user can then edit the data in the text fields which updates the appropiate row or enters data into the bottom (blank) text fields which adds a new row.

This is the query I have to call the data PHP Code:

Editor To Create Table From MySQL
Does anyone know of a Windows editor I can use to design a table from
a MySQL database?

I have a end-user catalog I need to create. Nothing fancy - just
display a few fields. I could hand code it, but do not have the time
to relearn all the sql. No shopping-cart or anthing, just display
fields.

Create A Table From A Mysql Query
How would you create a table from a mysql query, but limit the amount of values on each row.

Create A Table In MySQL From A .php File
Is it possible to create a mySQL table from a .php file? If so how?

Possible To Create A Variable From The Results Of A Mysql Query?
I need to perform a mysql query,Take the results and create a loop for each item that returns, and then create a variable that will pull the complete results from the query to include into a template. here is the code I am woring with PHP Code:

How Do I Create A PHP And MySQL Change Password Form With MD5?
Summary:
I a beginner with PHP and I am creating a secure customer portal using php and MYSQL I am using logon scripts and storing passwords with MD5 encryption.

I am able to:
get the password to be stored into the database as MD5 and the user can log in sucessfully.

My problem:
Comes when I am trying to make a password reset form where I (the admin) can change the users password to a temporary password (cant figure out how to do this), then the user can logon with the temporary password and change the temporary password to a new one.(cant figure out how to do this either). The variable does hold the hash, but its not being updated in MySQL.

The Code:
I am trying to use the following command with no luck:
$query = "UPDATE user SET `password`='$newpassword' WHERE id='$id'";
$result = mysql_query($query);

Am I doing somthing wrong? I have tried many differnt version and ways to do this with none being sucessful.

PHP Script To Create MySQL DB From A Dump FIle
I just need to write a script that will read a dump file and just create the tables, ect. as specified from it. If anyone has a link or some simple code for this that would be great. Didn't think about this till i had done it, but i have the mysql create commands over multiple lines, so I can't just use:

while (list($lineNum, $line) = each($dumpFile)) {
mysql_query($line);}

How Do You Create Foreign Key Constraints In MySQL? Or Close To It?
create table if not exists nnet_produkt_varegruppe (
nnet_produkt_varegruppe_id int not null auto_increment,
primary key(nnet_produkt_varegruppe_id),
nnet_produkt_varegruppe_navn varchar(255) not null
);

create table if not exists nnet_produkt_farge (
nnet_produkt_farge_id int not null auto_increment,
primary key(nnet_produkt_farge_id),
nnet_produkt_farge_code varchar(5) not null,
nnet_produkt_farge_navn varchar(255) not null
);

alter table nnet_produkt_farge add index
ix_nnet_produkt_farge_code(nnet_produkt_farge.nnet _produkt_farge_code);

create table if not exists nnet_produkt_storrelse (
nnet_produkt_storrelse_id int not null auto_increment,
primary key(nnet_produkt_storrelse_id),
nnet_produkt_storrelse_navn varchar(255) not null
);

create table if not exists nnet_produkt (
nnet_produkt_id int not null auto_increment,
primary key(nnet_produkt_id),
nnet_produkt_varenr varchar(50) not null,
nnet_produkt_navn varchar(255) not null,
nnet_produkt_farge_code varchar(5),
nnet_produkt_storrelse_id int default 0,
nnet_produkt_kvalitet_id int default 0,
nnet_produkt_krage varchar(255),
nnet_produkt_innpris decimal(6,2) not null,
nnet_produkt_utpris decimal(6,2) not null,
nnet_produkt_netto decimal(6,2) not null,
nnet_produkt_forhandler_rabatt decimal(6,2) not null,
nnet_produkt_bonus decimal(6,2) default 0.00,
nnet_produkt_toppbonus decimal(6,2) default 0.00,
nnet_produkt_bto decimal(6,2) default 0.00,
nnet_produkt_quantity int default 0
);

alter table nnet_produkt add index
ix_nnet_produkt_varenr(nnet_produkt_varenr);
alter table nnet_produkt add index ix_nnet_produkt_navn(nnet_produkt_navn);
alter table nnet_produkt add index
ix_nnet_produkt_fargecode(nnet_produkt.nnet_produk t_farge_code);
alter table nnet_produkt add index
ix_nnet_produkt_storrelse_id(nnet_produkt_storrels e_id);
alter table nnet_produkt add index
ix_nnet_produkt_innpris(nnet_produkt_innpris);
alter table nnet_produkt add index
ix_nnet_produkt_utpris(nnet_produkt_utpris);
alter table nnet_produkt add index
ix_nnet_produkt_netto(nnet_produkt_netto);
alter table nnet_produkt add index
ix_nnet_produkt_forhandler_rabatt(nnet_produkt_for handler_rabatt);
alter table nnet_produkt add index
ix_nnet_produkt_bonus(nnet_produkt_bonus);
alter table nnet_produkt add index
ix_nnet_produkt_toppbonus(nnet_produkt_toppbonus);
alter table nnet_produkt add index ix_nnet_produkt_bto(nnet_produkt_bto);
alter table nnet_produkt add index
ix_nnet_produkt_quantity(nnet_produkt_quantity);

I cannot create the indices I need considering the schema structure I am
listing. How on earth do I create something like a foreign key constraints
if it doesn't let you?

Query Mysql, Return Highest Value Then Create Value +1
I have a product input form I created (with php freaks help) for my website which I input general information and specs on our products. What I'd like to do now is when that form loads, it searches a seperate table and looks for the highest "ID" number.

It returns the number, adds 1 to it and displays the number somewhere on the input form for reference + error checking. When the form is submitted it takes that form and creates a record pushing that number in the correct field.

Dynamically Generate MySql Create Index Statements
I know in mySql you can run "show indexes from TableName" and it will show you a list of all the index's for that table. What I would like to do is run this query to generate a create index statement that I can run on another database all thru PHP. Has anyone allready built something like this in PHP to post some code?

mysql> SHOW INDEXES FROM reviews;
+---------+---------------+--------+------+------------+---------+
| Table   | Column_name   | Packed | Null | Index_type | Comment |
----------+---------------+--------+------+------------+---------+
| reviews |  id           | NULL   |      | BTREE      |         |
| reviews |  data         | NULL   | YES  | FULLTEXT   |         |
+---------+---------------+--------+------+------------+---------+
2 rows in set (0.01 sec)

Image Upload, Resize, Rename And Create Record In Mysql
I have limited knowledge in php and I am having trouble with uploading
an image to a remote directory and resizing it if it's larger and
renaming it to a unique id, while at the same time I would like to
create a record in mysql database. I've tried to find some tutorials
but I've had trouble finding any good ones. Wondering if anybody has
good examples or link to a good tutorial.

Warning: MySQL Connection Failed: Can't Create IP Socket (10036)
I have a Problem with together MySQL, PHP3 and Apache-Server on Windows95. I run Apache-Server as Webserver, also on this machine runbs MySQLWIN32. Ihave written a simple PHP3 code as follows: Code:

Create A Button To Export A Mysql Table To An Excel File.
Does anyone have the code that creates a link, and on click, takes a specified table in my database and exports and downloads an excel file?

Nested MySQL Queries Create Issue With Validity Of Result Index?
I am iterating through a result set to generate a second set of queries but
no matter what I do I get the error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource

even though if I echo the query to the browser and cut and paste it into the
command line I get valid results.

Do I have to store the first result in an array before doing the second set?

while ($i < mysql_num_rows($result)) {
$PIDs[$id]['ClientName'] = $client;
$PIDs[$id]['ProjectName'] = mysql_result($result, $i, 'Name');
$PIDs[$id]['PID'] = mysql_result($result, $i, 'PID');
$thisPID = $PIDs[$id]['PID'];
$PIDresult = ("SELECT * from hours WHERE PID = '$thisPID'") or
die(mysql_error());
$j=0;
while ($j < mysql_num_rows($PIDresult)) {
$PIDs[$id]['PID']['Comments'] = mysql_result($PIDresult, $j,
'Comments');
$j++;
}
$i++;
}
}

Copy And Paste On MySQL To MySQL Database
Would there be any issues if i literary Copy and Paste a mysql db from one server to another mysql db server? When i say "copy and paste" is just like tranferring one word doc from one pc to another pc.

I tried the copy and paste already and the new server had recognize the DB i had pasted. I just want to confirm if there would be issues doing it so.. Or should i use Mysql.com Migration toolkit?

Php/Mysql- Uploading Mysql Database
I've set up a basic database using Mysql (just creating a web blog I followed a tutorial) and then started writing the php code for interacting with the database. how do I put the Mysql database onto the the web server where I have server space (the server I use is just some company that I pay €100 a year for). I need the php file to get the data from the Mysql database...

Getting A Value From MYSQl Database
I want to get the value from a field in the database using the following PHP code:

$sql = "SELECT Paper_id from Papers WHERE Title= '$Paper_Title'";
$PaperID = mysql_query($sql);

However this returns some wierd response: "Resource id #2" how do I just get the value of the field in my new selected table which is 1*1.

Help With MySQL Database Retrieval
I am a total newbie and I am having problems retrieving multiple rows from a database...

when I try to get a printout of the whole table, I get the following error:

Warning: 0 is not a MySQL result index in C:HTTPDHTDOCStest.php3
My code is as follows:

<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("test",$db);
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=1>n";
echo "<tr><td>Name</td><td>Position</td></tr>n";
do {
printf("<tr><td>%s %s</td><td>%s</tr>n", $myrow["first"], $myrow["last"], $myrow["address"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>n";
} else {
echo "Sorry, no records were found!";
}
?>

Check To See If Value Is Already In Mysql Database
I am looking for the most efficient way to check and see if an inputed email (via form) is already in the database under the column 'Email'.

Pdf Files In A Mysql Database
I have a mysql database which I reach with php-code.

I want to be able to download and open files I have stored(as a BLOB) in the database. Downloading and opening word documents and textfiles give no problems, but PDF-files aren't possible to open.

Has anybody the same troubles, or does anybody know a solution for this problem?

Insert Into Mysql Database
It sounds very simple, but for some reason I just can't figure it out, and it will save a lots of time to me, if someone can direct me into the right direction. I was trying to input data into mysql table through post method, but it was not working. I made it simple and just tried to enter anything from a php file, but it does not work, so there is something that i am doing wrong with the insertion query.

$link = mysql_connect($hostName, $userName, $password);
echo("connected");

mysql_select_db($databaseName, $link);
echo("database selected");
echo ($databaseName);

mysql_query("INSERT INTO image VALES('','','','','','','','','', 'hello', '', '', '','','','','')", $link);

echo ("done");

I am trying to enter into one of those fields, but it does not populate the table in mysql database.

Cant Connect To Mysql Database
I'm having a problem connecting to a database, when i use the following script to connect to a database (all the login details are correct) it connects to mysql but says it can't connect to the database any body got any suggestions...

Creating A New MySQL Database
I run a small horse racing based website that has a 'fantasy league' type competition each season. Last year i looked after all the entries, leaderboards etc.. using excel and copying and pasting to webpages each week.

However this year i am going to attempt to use MySQL and PHP to have it automatic bar result entry. I have built a basic php and MySQL site before with the usual insert, edit etc.. But this one will need features im not sure how i go about making.

Basically there will be a list of horses (around 150) divided into 4 grades. Entrants pick 2 horses from each grade so a total of 8 horses. Winning horses score 5, 2nd = 3 and 3rd =1.

I was thinking of having the following 2 tables - one for the horses - listing their name and grade. One for entrants - the peoples contact details and their chosen horses.

However from there im not sure how to able to enter the latest results and how i can create a leaderboard page and list the points each horse has. I was thinking of a new table with a row for each result showing horse name and points scored but i then dont't know how this table can be used to create a column on the horse table that lists each horses total points. And also how it can be used to create the total points each entranant has got so far (i.e. the total point for all 8 of their horses)

Mysql Database Problem
I installed php4,MySQL,Apache on my Windows98 system. Everything works up to the point of connecting to Mysql. Then I can't get it to do anything else.
this works to connect:

$connection = mysql_connect("localhost", "user", "xxxxxxxx")
or die ("couldn't connect");
if ($connection) {
$msg = "success!";}?>
But when I try to anything like create a database I get the errors (in this case 'couldn't create database'.)

<?
$new_db = "cosmos";
$connection = @mysql_connect("localhost", "user", "xxxxxxxxx") or die ("Couldn't connect.");
$result = @mysql_create_db($new_db,$connection) or die ("Couldn't create database");
if ($result) {$msg = "<p>Database has been created</p>";}?>


Copying From One Mysql Database To Another
Is it possible to open a connection to two separate mysql databases in order to copy the data from one table in the first database into a table in the second database? I'm assuming the answer is yes, but I'm confused as to the proper php syntax.

Pictures Into A MySQL Database
I need to put pictures in to a MySQL -database with PHP and also be able to view them on a web page with PHP.

How I Setup My Mysql Database(s)...
Quick question on how I setup my mysql database(s)...

If my setup is such that I have multiple clients, and each client gets
10 tables to store their data, is it better for performance if I put all
of these tables into 1 large database (with a unique identifier
prepended to each one) or create a separate database for each client?
i.e., assuming 1000 clients, I either would have:

A) 1 database and 10,000 tables in it, 10,000 total tables

B) 1000 databases with 10 tables in each, 10,000 total tables

Intuition tells me that the multiple databases would be better for
isolating data between clients, but I am not sure if this would slow
things down.

All the info I found on this online was inconclusive and mostly was
people speculating, so I hoped you all could help more.

MySQL Country Database
Is there anyone out there willing to donate their country table fora web database. I have been looking all over for a sql script to create a country table populated with recent data, but I just can't seem to find one. People must do this ALL the time.

Parsing PHP From A MySQL Database
i am creating a CMS and i have a setup so you can add sections and they get stored in a db then you can call them with index.php/section. however this doesn't work right if you have PHP in the content of the section. the PHP code shows up instead of getting parsed.
PHP Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved