This document provides an overview of MySQL and how it relates to PHP. It discusses MySQL constants for fetching data, common PHP MySQL functions like mysql_connect() and mysql_select_db(), and examples of how to connect to a MySQL database, select a database and table, fetch and display data, insert new data, and close the connection. It also includes information about PHP MySQL training provided by CBitss Technologies in Chandigarh, India.
1 of 13
Downloaded 11 times
More Related Content
Php verses my sql
2. Introduction
? What is MySql ?
MySql is an open source relational database
management system.
? How MySql is related to PHP?
MySql acts as a back-end database server and
helps in data storage and management of data
stored at MySql database server.
3. Predefined Constant
MySql Fetch Constant :
? MYSQL_ASSOC : Columns are returned into the array
having the fieldname as the array index.
? MYSQL_BOTH : Columns are returned into the array
having both a numerical index and the field name as the array
index.
? MYSQL_NUM : Columns are returned into the array having
a numerical index to the fields. This index is start with 0, the
first field in the result.
4. PHP MySql Function
mysql_connect : Open a connection to a MySql server.
mysql_close : Close MySql connection.
mysql_create_db : Create a MySql database.
mysql_error : Returns the text of the error message
from previous MySql operation.
mysql_fetch_assoc : Fetch a result row as an
associative array.
mysql_select_db : Select a MySql database.
5. How to connect to MySql via PHP.
<?php
$host = "localhost";
$username = "root";
$password = "";
mysql_connect($host,$username,$password)
or die(mysql_error());
?>
6. How to Select database in a table.
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dbemp") or die(mysql_error());
$result=mysql_query("select * from emp")
or die(mysql_error());
$row=mysql_fetch_array($result);
echo "<br>Roll:".$row['empno'];
echo "<br>Name:".$row['name'];
echo "<br>Roll:".$row['Job'];
?>
7. How to select values from MySql table.
<?php
mysql_connect("localhost", "root", "") or
die(mysql_error());
mysql_select_db("dbemp") or die(mysql_error());
$result=mysql_query("select * from emp")
or die(mysql_error());
echo "<table width='20%' bgcolor='lime' border='4'
bordercolor='green'>";
echo "<tr> <th>Empno</th> <th>Name</th> </tr>";
12. CBitss Technologies provide a PHP training
in Chandigarh. A well qualified trainer will
train you on all sophisticated technologies.
CBitss Technologies is ISO 9001:2008
certified PHP training institute in
Chandigarh.