Sunday, September 15, 2013

Giving to the MySQL Query

Once we select the database in which we will work, then we can give
query commands such as SELECT, DELETE, CREATE, UPDATE. Here's an example PHP script
for example create a table in the test database.
<? php
mysql_connect ("localhost", "admin", "1admin") or die (mysql_error ());
mysql_select_db ("test") or die (mysql_error ());
mysql_query ("CREATE TABLE example (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR (30),
age INT)
PRIMARY KEY (id) ")
or die (mysql_error ());
echo "The table has been created";
?>

In the example above, it can be seen that the PHP command to write the query to MySQL
is
mysql_query ("query");
While the following sample script to insert 2 pieces of records / data to the table example.
<? php
mysql_connect ("localhost", "admin", "1admin") or die (mysql_error ());
mysql_select_db ("test") or die (mysql_error ());
mysql_query ("INSERT INTO example (name, age)
VALUES ('dear', 20) ");
mysql_query ("INSERT INTO example (name, age)
VALUES ('Surti', 30) ");
echo "Data has been entered";
?>

news sources from :Rosihan Ari Yuana

No comments:

Post a Comment