PHP Mysql tutorial for beginners with examples code and tip for query with select commans ,
insert delete update with mysql_query();
Example PHP Mysql for Connect Database (PHP Mysql tutorial for beginners)
you can use function mysql_connect(); to connect to mysql dbms by send db host , db user , db password
and use function mysql_select_db(); to connect to databalse by send database name for example
$username="dbuser";
$password="dbpassword";
$database="mydatabase";
mysql_connect("localhost",$username,$password);
//select database if fail print error
@mysql_select_db($database) or die( "Unable to select database");
Example PHP Mysql for Query with SQL command (PHP Mysql tutorial for beginners)
you can execute any SQL command by sending parameter to functoin mysql_query();
for example in query it's will return data in mysql_result();
$query="select * from test_comment where flash_id='$code_id' order by comment_id desc";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$content =mysql_result($result,$i,"content");
echo "
".$content;
}
Example PHP Mysql for Insert with SQL command (PHP Mysql tutorial for beginners)
for Insert mode it's easy way to using function mysql_query(); to execute SQL command with insert statement example code in below
$query = "insert into test_comment (flash_id,content,post_by,create_date,last_update,ip) ";
$query.="values('$flash_id','$content2','$post_by','$_date','$_date','$ip')";
mysql_query($query);
Example PHP Mysql for Delete with SQL command (PHP Mysql tutorial for beginners)
for delete mode it's the same way by using mysql_query(); example code in below\
$query = "delete from test_comment ";
mysql_query($query);
Example PHP Mysql for Update with SQL command (PHP Mysql tutorial for beginners)
for update mode it's the same
$query = "update test_comment set title='test' where code_id='1001'";
mysql_query($query);
Tip : With PHP and MySQL you can only using mysql_query(); you can send any SQL command to execute