Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP provides mysql_connect function to open a db connection
- This function takes 5 parameters.
- 1.server
- 2.user
- 3.passwd
- 4.new_link
- 5.client_flags
- <?php
- $dbhost='localhost:8080';
- $dbuser='root';
- $dbpass='root';
- $conn=mysql_connect($dbhost,$dbuser,$dbpass);
- if(!$conn)
- {
- die('could not connect:'. mysql_error());
- }
- echo 'connected successfully';
- $sql='CREATE Database test_db';
- $retval=mysql_query($sql,$conn)
- if(!$retval)
- {
- die('Could not create db:'. mysql_error());
- }
- echo "db created";
- $sql='CREATE TABLE employee('.
- 'emp_id INT NOT NULL AUTO_INCREMENT,'.
- 'emp_name VARCHAR(20) NOT NULL,'.
- 'emp_address VARCHAR(20) NOT NULL,'.
- 'emp_salary INT NOT NULL,'.
- 'join_date timestamp(14) NOT NULL,'.
- 'primary key(emp_id))';
- mysql_select_db('test_db')
- $retval=mysql_query($sql,$conn)
- if(!$retval)
- {
- die('Could not create table:'. mysql_error());
- }
- echo "table created successfully";
- mysql_close($conn);
- ?>
- ?>
Add Comment
Please, Sign In to add comment