Write PHP Script for the following Creating connection with

Write PHP Script for the following Creating connection with MySQL Creating database tables Employee(emp_id:emp_name;emp_address:emp_salary, join_date, salary) Select database table Employee(emp_id:emp_name:emp_address:emp_salary, join_date:salary)

Solution

Ans 1>

<?php
$server_name = \"localhost\";
$user_name = \"username\";
$passwd = \"password\";

// Create connection
$conn = new mysqli($server_name, $user_name, $passwd);
if(! $conn )
{
die(\'Could not connect: \' . mysql_error());
}
echo \'Connected successfully\';
$sql = \"CREATE TABLE Employee(
emp_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
emp_name VARCHAR(100) NOT NULL,
emp_address VARCHAR(200) NOT NULL,
emp_salary INT NOT NULL,
join_date DATE,
emp_salary INT NOT NULL) \";
mysql_select_db( \'Employee\' );
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die(\'Could not create table: \' . mysql_error());
}
echo \"Table created successfully\ \";
mysql_close($conn);
?>

Ans 2>

<?php
$server_name = \"localhost\";
$user_name = \"username\";
$passwd = \"password\";

// Create connection
$conn = new mysqli($server_name, $user_name, $passwd);
if(! $conn )
{
die(\'Could not connect: \' . mysql_error());
}
echo \'Connected successfully\';
$sql = \"SELECT emp_id,emp_name,emp_address,
emp_salary,join_date,salary
FROM Employee\";
mysql_select_db(\'Employee\');
$retval = mysql_query($sql, $conn);
if(! $retval )
{
die(\'Could not get data: \' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo \"Employee ID :{$row[\'emp_id\']} <br> \".
\"Employee Name: {$row[\'emp_name\']} <br> \".
\"Employee Address: {$row[\'emp_address\']} <br> \".
\"Employee Salary : {$row[\'emp_salary\']} <br> \".
\"Join Date : {$row[\'join_date\']} <br> \".
\"Salary : {$row[\'salary\']} <br> \".
\"--------------------------------<br>\";
}
echo \"Fetched data successfully\ \";
mysql_close($conn);
?>

 Write PHP Script for the following Creating connection with MySQL Creating database tables Employee(emp_id:emp_name;emp_address:emp_salary, join_date, salary)
 Write PHP Script for the following Creating connection with MySQL Creating database tables Employee(emp_id:emp_name;emp_address:emp_salary, join_date, salary)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site