Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL); ini_set('display_errors', 1);
  3. mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  4.  
  5. //Database variables
  6. $servername = "localhost";
  7. $username = "Somename";
  8. $password = "Verysecret";
  9. $dbname = "TESTDB";
  10. $temptable = "tablename";
  11.  
  12. //Open database
  13. $conn = new mysqli($servername, $username, $password,$dbname);
  14.  
  15. if ($conn->connect_error) {
  16. die("Connection failed: " . $conn->connect_error);
  17. }
  18. echo "Connected successfully to database: ",$dbname,"<br>" ;
  19. ?><br><?php
  20.  
  21. //Create table if not existing yet (syntax error here?)
  22. echo "Creating table if non existing","<br>";
  23. $conn->select_db('$dbname');
  24. $sql = "CREATE TABLE IF NON EXIST `{$temptable}` (
  25. `xml_date` datetime,
  26. `xml_duration` int(2),
  27. `xml_boat` VARCHAR(30),
  28. `xml_itinerary` VARCHAR(30),
  29. `xml_dep_arr` VARCHAR(30),
  30. `xml_spaces` INT(2),
  31. `xml_rate_eur` decimal(4,2),
  32. `xml_rate_gbp` decimal(4,2),
  33. `xml_rate_usd` decimal(4,2))";
  34.  
  35. //This part not showing up in output at all!
  36. if(mysqli_query($conn, $sql)){
  37. echo "Table created successfully";
  38. } else {
  39. echo "Table is not created successfully ";
  40. }
  41.  
  42. //Deleting rows if table existed already (same syntax error here?)
  43. echo "Making sure table is empty","<br>";
  44. $sql = "DELETE * FROM `{$temptable}`";
  45.  
  46. mysqli_close($conn);
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement