Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. string mysql_error ([ resource $link_identifier ] )
  2.  
  3. <?php
  4. $server = "localhost";
  5. $database = "database";
  6. $username = "user";
  7. $password = "password";
  8.  
  9. $mysqlConnection = mysql_connect($server, $username, $password);
  10. if (!$mysqlConnection)
  11. {
  12. echo "Please try later.";
  13. }
  14. else
  15. {
  16. mysql_select_db($database, $mysqlConnection);
  17. }
  18. ?>
  19.  
  20. <?php
  21. $username = 'user';
  22. $password = 'password';
  23. $server = 'localhost';
  24. // Opens a connection to a MySQL server
  25. $connection = mysql_connect ($server, $username, $password) or die('try again in some minutes, please');
  26. //if you want to suppress the error message, substitute the connection line for:
  27. //$connection = @mysql_connect($server, $username, $password) or die('try again in some minutes, please');
  28. ?>
  29.  
  30. $servername='localhost';
  31. $username='root';
  32. $password='';
  33. $databasename='MyDb';
  34.  
  35. $connection = mysqli_connect($servername,$username,$password);
  36.  
  37. if (!$connection) {
  38. die("Connection failed: " . $conn->connect_error);
  39. }
  40.  
  41. /*mysqli_query($connection, "DROP DATABASE if exists MyDb;");
  42.  
  43. if(!mysqli_query($connection, "CREATE DATABASE MyDb;")){
  44. echo "Error creating database: " . $connection->error;
  45. }
  46.  
  47. mysqli_query($connection, "use MyDb;");
  48. mysqli_query($connection, "DROP TABLE if exists employee;");
  49.  
  50. $table="CREATE TABLE employee (
  51. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  52. firstname VARCHAR(30) NOT NULL,
  53. lastname VARCHAR(30) NOT NULL,
  54. email VARCHAR(50),
  55. reg_date TIMESTAMP
  56. )";
  57. $value="INSERT INTO employee (firstname,lastname,email) VALUES ('john', 'steve', 'johnsteve@yahoo.com')";
  58. if(!mysqli_query($connection, $table)){echo "Error creating table: " . $connection->error;}
  59. if(!mysqli_query($connection, $value)){echo "Error inserting values: " . $connection->error;}*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement