PHP and MySQL?HOW TO?
|
Hi guys, PLZ help me... I have made a forum just by using PHP and JavaScript files where I have made a PHP function to read and write in a JavaScript Array!!!(http://members.lycos.co.uk/yssef/MON) I know it would not work while user number is increasing So, I want to use MySQL!! BUT, HOW to use PHP to send data to MySQL database??? THKZ 4 all Youssef Gamil,15 years old,Male,Alexandria-Egypt.That's all YoGa |
Re: PHP and MySQL?HOW TO?
Link |
by
![]() |
step 1: you need to setup your database. if you have access to a mysql server, you will need to issue a CREATE DATABASE query. step 2: create your table schema. think about what tables you need, and issue CREATE TABLE queries for them. also, setup indexes where applicable. step 3: do a test connection to your database. see php.net/mysql_connect for more info. step 4: code your forum's functionality in mysql. you may want to write a database abstraction layer! ![]() ![]() ![]() |
Re: PHP and MySQL?HOW TO?
Link |
by
![]() |
I don't really remember any of the php or mysql I once knew, but I learned it all from this really awesome book. It explains exactly what you just asked about and much more. |
Re: PHP and MySQL?HOW TO?
Link |
by
![]() |
that is indeed a good book. but, the language references can be just as good if you are skilled at using them and know what it is your trying to do. that, i guess, is the hard part after all! a little hint on the DB structure: one topic contains many threads, one thread contain many posts. one user can make many posts. there isnt much else to it! ![]() ![]() ![]() |
Re: PHP and MySQL?HOW TO?
|
This isn't the answer of my question!!! All I need is how to write PHP code which will UPDATE/DELETE/INSERT data to a database (MySQL)? YoGa |
Re: PHP and MySQL?HOW TO?
|
Create a table: mysql_query("CREATE TABLE [TABLE NAME] ([COLUMN NAME] [DATA TYPE] [EXTRA INFO], ...") or die(mysql_error()); ex. mysql_query("CREATE TABLE 'myTable' ( 'colOne' int(20) NOT NULL DEFAULT '0', 'colTwo' varchar(20) NOT NULL DEFAULT '', 'colThree' int(20) NOT NULL auto_increment, PRIMARY KEY ('colThree') )") or die(mysql_error()); (Would create a table named 'myTable' with columns 'colOne', 'colTwo', and 'colThree'. The auto_increment would automatically increment colThree by one starting from zero every time you insert a new row. The PRIMARY KEY marks 'colThree' as the row number for your current entry) Insert row into table: mysql_query("INSERT INTO [TABLE NAME] ([COLUMN(s)], ...) VALUES ([COLUMN VALUE], ...)") or die(mysql_error()); ex. mysql_query("INSERT INTO 'myTable' ('colOne','colTwo') VALUES ('16', 'Hello')") or die(mysql_error()); (Would insert the values 16 and 'Hello' to the last row of the table 'myTable' at their corresponding column) Update values: mysql_query("UPDATE [TABLE NAME] SET [VALUE(s)] = [NEWVALUE], ... WHERE [SOMEVALUE] = [SOMETHING]")or die(mysql_error()); ex. mysql_query("UPDATE 'myTable' SET colOne = '20', colTwo = 'Goodbye' WHERE colThree = '1'") or die(mysql_error()); (Would update the values of myTable where 'colThree' is equal to '1') If you'd like more information, you can search http://www.mysql.com/ Hope this helps. ^^ |
Re: PHP and MySQL?HOW TO?
|
THANKS MUCH :D :D YoGa |
Re: PHP and MySQL?HOW TO?
|
http://forum.persiantools.com/f23.html check it..it a PHP/MySQL YoGa |
Re: PHP and MySQL?HOW TO?
|
It that the code which I were searching for: $mysql = mysql_connect("YOURHOST", "USERNAME", "PASSWORD"); mysql_select_db("DATABASENAME"); $query = "select content from TABLE_NAME where id = PAGEID"; $result = mysql_query($query); $page = mysql_fetch_array($result); echo $page["content"]; ?> It was very hard to get it from that website.. It was written in Persian..(THE SAME ARABIC LETTERS!!!!!!!!!). SORRY NEVER CHECK IT..you may understand nothing as me!! lol YoGa |
Re: PHP and MySQL?HOW TO?
Link |
by Aoi Azzura
on 2005-09-21 23:30:14
|
Same thing, but I usually add mysql error message $host="[fill it with your host name]"; $user="[fill it with your user name in the MySQL database]"; $pass="[fill it with your password for your username in the MySQL database]"; $db="[fill it with the database you wish to use]"; $connect=mysql_connect($host,$user,$pass) or die(mysql_error()); ?> If I'm not mistaken... |