Getting Started: Combined Operation of PHP and MYSQL_PHP Tutorial

WBOY
Release: 2016-07-13 17:29:46
Original
746 people have browsed it

, connect to database

$dbhost = localhost;
$dbuser = root; //Your mysql username
$dbpass = 123456; //Your mysql password
$dbname = data; // Your mysql library name

//Connect to local database
$GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass);

//Open the database
mysql_select_db($dbname,$GLOBALS["conn"]);

?>

2. Read the value of a certain field in the database

//Read a column of data
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);

printf("Username: %s
", mysql_result($result,3,"UserName"));
printf("Password: %s
", mysql_result($result,3,"UserPass"));

?>

3, insert a certain piece of data

$sql="insert into ec_admin(UserName,UserPass) values(liugongxun2,jakemary2)";
$result=mysql_query($sql,$GLOBALS["conn"])or die(mysql_error());

?>

4, while loop

$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
while($myrow = mysql_fetch_row($result))
{
printf("Username %s %s password
",$myrow[1],$myrow[2]);
}

?>

5,do while loop

$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
if($myrow = mysql_fetch_array($result))
{
do
{
printf("Username %s %spassword
",$myrow["UserName"],$myrow["UserPass"]);
}while($myrow = mysql_fetch_array($result));
}
?>

6, determine whether the form is submitted

if ($submit)

{}

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531667.htmlTechArticle, connect to the database?php $dbhost = localhost; $dbuser = root; //Your mysql username $dbpass = 123456; //Your mysql password $dbname = data; //Your mysql library name //Connect to the local database...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!