Back | Reverse | Quick Reply | Post Reply |

PHP and MySQL?HOW TO?
Link | by YoGa on 2005-08-14 15:22:44
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 gendou on 2005-08-14 16:56:55
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 psoplayer on 2005-08-14 19:03:57 (edited 2005-08-14 19:05:15)
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 gendou on 2005-08-14 23:14:11
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?
Link | by YoGa on 2005-08-15 04:52:27
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?
Link | by Inggo on 2005-08-15 06:04:04 (edited 2005-08-24 15:05:03)
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?
Link | by YoGa on 2005-08-15 14:34:23
THANKS MUCH :D :D

YoGa

Re: PHP and MySQL?HOW TO?
Link | by YoGa on 2005-08-17 13:58:36
http://forum.persiantools.com/f23.html
check it..it a PHP/MySQL

YoGa

Re: PHP and MySQL?HOW TO?
Link | by YoGa on 2005-08-17 14:09:28
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...


Back | Reverse | Quick Reply | Post Reply |

Copyright 2000-2025 Gendou | Terms of Use | Page loaded in 0.0010 seconds at 2025-05-28 19:39:36