Re: [PHP-DB] Trying to add primary key to existing database.
hehe, ok i would write a script that reads the existing data from the table and inserts it into a new one that has the same structure PLUS a primary key something like: original_table:name, description, whatever new_table:id, name, description, whatever where id is primary key and auto_increment then ? if ($link=mysql_connect(host,user,pw) { mysql_select_db(the_correct_database); $result=mysql_query(SELECT * FROM original_table); while (list($name,$description,$whatever) = mysql_fetch_row($result)) { mysql_query(INSERT INTO new_table (name,description,whatever) VALUES ($name,$description,$whatever)); //that should add the id automatically } mysql_close($link) ? then you can drop the original_table and rename the new_table to original_table i don't know if there's a better, more simple solution and i hope i did not forget anything important and it works this way Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Trying to add primary key to existing database.
Hi. I don't know cPanel, but I expect it can run SQL directly, most panels can. Use the ALTER TABLE ADD {INDEX|KEY} syntax to add indexes/primary keys. You can use multiple columns, which together form a unique value to create your primary key. Niel -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] OLAP Multidimensional databases and PHP
Hello... I'm the kind of PHP guy that people is scared of... i am Too curious :D. So lately at the company i've been working for like 6 months, they are going to migrate a OLAP program, to vb.net, since i think php could do a better work... since it can be expanded... well i was looking for information about how to work with OLAP and PHP, but that's not all.. i also would like to know if someone here knows about multidimensional databases~ and could explain me a lil bit... i've got some vague ideas... but they arent that good for me to explain very well... Note that this program its called Rotator it has 2 parts, the Modeler (The one which builds your tests), and the analyzer (The one who takes your tests, and lets you analyze it via OLAP) its a very powerfull tool... and welll... my boss (He did the whole thing in Vb) agreed to work with it under BSD licence if he can do it with PHP... so consider the BOOM thatr something like this will help PHP and more the Opensource comunity... Anyone interested in helping?~ Can anyone tellme where to go?... i really wanna know how to work with olap and multidimensional databases, not just for teh fact of the rotator's migration, but for the knowledge it has...
Re: [PHP-DB] Trying to add primary key to existing database.
Chris Carter wrote: Hi, I have a database, which was till now, not having any primary key defined. I thought I would not need it but now I think I do (based on the suggestions from my prior postings). I am now trying to insert the primary key in an already existing database. There was not even an index defined earlier (sorry, if it looks strange). There are many columns that have same names this means that I cannot make that column the primary key. I have now got an idea to first define index on the table and then make the index thing the primary key. I have mySql on cPanel. please advice how to achieve this on an existing database in cPanel php admin. Any link or steps would help. I tried it myself but there is something it wants to tell me, that I am not sure about. Most likely not everything can be done through phpmyadmin, however you can add your own primary key easily: alter table tablename add id int not null auto_increment primary key; See http://dev.mysql.com/doc/refman/4.1/en/alter-table.html -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Trying to add primary key to existing database.
Christopher Blöcker wrote: hehe, ok i would write a script that reads the existing data from the table and inserts it into a new one that has the same structure PLUS a primary key something like: original_table:name, description, whatever new_table:id, name, description, whatever where id is primary key and auto_increment then ? if ($link=mysql_connect(host,user,pw) { mysql_select_db(the_correct_database); $result=mysql_query(SELECT * FROM original_table); while (list($name,$description,$whatever) = mysql_fetch_row($result)) { mysql_query(INSERT INTO new_table (name,description,whatever) VALUES ($name,$description,$whatever)); //that should add the id automatically } mysql_close($link) ? then you can drop the original_table and rename the new_table to original_table i don't know if there's a better, more simple solution and i hope i did not forget anything important and it works this way Good idea but you can put that all into one step and leave php out altogether: insert into table (f1, f2, f3) select f1,f2,f3 from other_table; See http://dev.mysql.com/doc/refman/4.1/en/insert-select.html (Nice bonus - this is sql standard so it works across a lot of different db's). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php