PHP training in Chandigarh
-
Upload
navneetsharma -
Category
Documents
-
view
49 -
download
0
description
Transcript of PHP training in Chandigarh
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.
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.
PHP MySql Functionmysql_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.
How to connect to MySql via PHP.<?php$host = "localhost";$username = "root";$password = "";mysql_connect($host,$username,$password) or die(mysql_error());?>
How to Select database in a table.
<?phpmysql_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'];?>
How to select values from MySql table.<?phpmysql_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>";
Contin…while($row = mysql_fetch_array( $result )) { echo "<tr> <td>";
echo $row['empno'];echo "</td> <td>"; echo $row['name'];echo "</td></tr>";
} echo "</table>";?>
Display data from database using fetch_assoc function
$sql = "SELECT empno, name,Job FROM emp";$result = $conn->query($sql);if ($result->num_rows > 0) {while($row = $result->fetch_assoc()) { echo "<br> Empno: ". $row["empno"]. " Name: ". $row["name"]. " Job:" . $row["Job"] . "<br>";} } else { echo "Can't find the record"; }$conn->close();?>
How to insert data in a MySql Table.
<?php$dbhost = 'localhost';$dbuser = 'root';$dbpass = '';$conn = mysql_connect($dbhost, $dbuser, $dbpass);if(! $conn ){ die('Could not connect: ' . mysql_error());}$sql = "INSERT INTO emp (ename,job, sal) VALUES ('Amit','manager','3333')";
Contin…
mysql_select_db('dbemp');$retval = mysql_query( $sql, $conn );if(! $retval ){ die('Could not enter data: ' . mysql_error());}echo "Entered data successfully\n";mysql_close($conn);?>
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.
Office : SCO 23-24-25, Level 3 , Near Passport office, Above Allahabad Bank, Sec 34A,Chandigarh. Phone : 9988741983Website : http://goo.gl/aO9a4u Email : [email protected]