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 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.
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. <?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']; ?>
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>";
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 successfullyn"; 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 : 9988741983 Website : http://goo.gl/aO9a4u Email : navneetlinuxexpert@gmail.com

Php verses MySQL

  • 2.
    Introduction • What isMySql ? 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 FetchConstant : • 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 connectto MySql via PHP. <?php $host = "localhost"; $username = "root"; $password = ""; mysql_connect($host,$username,$password) or die(mysql_error()); ?>
  • 6.
    How to Selectdatabase 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 selectvalues 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>";
  • 8.
    Contin… while($row = mysql_fetch_array($result )) { echo "<tr> <td>"; echo $row['empno']; echo "</td> <td>"; echo $row['name']; echo "</td></tr>"; } echo "</table>"; ?>
  • 9.
    Display data fromdatabase 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(); ?>
  • 10.
    How to insertdata 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')";
  • 11.
    Contin… mysql_select_db('dbemp'); $retval = mysql_query($sql, $conn ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } echo "Entered data successfullyn"; mysql_close($conn); ?>
  • 12.
    CBitss Technologies providea 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.
  • 13.
    Office : SCO23-24-25, Level 3 , Near Passport office, Above Allahabad Bank, Sec 34A,Chandigarh. Phone : 9988741983 Website : http://goo.gl/aO9a4u Email : navneetlinuxexpert@gmail.com