PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/scaffold/class.php

https://bitbucket.org/dynamikus/research-behavior-and-succes
PHP | 171 lines | 132 code | 37 blank | 2 comment | 15 complexity | 188497fccdbb91c8571719b443cd50a1 MD5 | raw file
Possible License(s): GPL-2.0, MIT
  1. <?php
  2. class mysql_funks
  3. {
  4. function connect_to_mysql(){
  5. $link=mysql_connect('localhost','root','root');
  6. if(!$link){
  7. die('Connection Faild: '.mysql_error());
  8. }
  9. }
  10. function table_field_information($query)
  11. {
  12. $select_db=mysql_select_db('scaffold');
  13. if(!$select_db){
  14. die('Database couldn\'t be selected '.mysql_error());
  15. }
  16. $result=mysql_query($query);
  17. $i=0;
  18. while($i<mysql_num_fields($result)){
  19. echo "Information for colum $i:<br />\n";
  20. $meta=mysql_fetch_field($result,$i);
  21. if(!$meta){
  22. echo "No information available<br />\n";
  23. }
  24. echo "<pre>
  25. blob: $meta->blob
  26. max_length: $meta->max_length
  27. multiple_key: $meta->multiple_key
  28. name: $meta->name
  29. not_null: $meta->not_null
  30. numeric: $meta->numeric
  31. primary_key: $meta->primary_key
  32. table: $meta->table
  33. type: $meta->type
  34. default: $meta->def
  35. unique_key: $meta->unique_key
  36. unsigned: $meta->unsigned
  37. zerofill $meta->zerofill
  38. </pre>";
  39. $i++;
  40. }
  41. mysql_free_result($result);
  42. }
  43. // Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead.
  44. function fetch_object($sql){
  45. $select_db=mysql_select_db('scaffold');
  46. if(!$select_db){
  47. die('Database selection faild: '.mysql_error());
  48. }
  49. $result=mysql_query("Select * from obs_forum_posts");
  50. while($row=mysql_fetch_object($result)){
  51. echo $row->id." : " ;
  52. echo $row->title. "<br />";
  53. }//end while
  54. mysql_free_result($result);
  55. }//end function
  56. function list_fields_table($db,$tablename){
  57. $select_db=mysql_select_db($db);
  58. if(!$select_db){
  59. die('Table selection faild: '. mysql_error());
  60. }//end if
  61. $result=mysql_query("SHOW COLUMNS FROM $tablename");
  62. if(!$result){
  63. die('Could not run query'. mysql_error());
  64. }//end if
  65. if(mysql_num_rows($result)>0){
  66. while($row=mysql_fetch_assoc($result)){
  67. print_r($row);
  68. }//end while
  69. }//end if
  70. }//end function list_fields_table
  71. function fetch_field(){
  72. $db_selected = mysql_select_db("scaffold");
  73. if(!$db_selected){
  74. die('Database selection faild'.mysql_error());
  75. }//end if
  76. $sql = "SELECT * from obs_forum_posts ";
  77. $result = mysql_query($sql);
  78. if(!$result){
  79. die('Query faild due to: '.mysql_error());
  80. }//end if
  81. echo "<table>";
  82. echo "<tr><td><b>Field name:</b></td> <td><b>Table name:</b></td> <td><b>Default value:</b></td>
  83. <td><b>Max length:</b></td> <td><b>Not NULL:</b></td> <td><b>Primary Key:</b></td> <td><b>Unique Key:</b>
  84. </td> <td><b>Mutliple Key:</b></td> <td><b>Numeric Field:</b></td> <td><b>BLOB:</b></td> <td><b>Field Type:</b></td>
  85. <td><b>Unsigned:</b></td> <td><b>Zero-filled: </b></td></tr>";
  86. while ($property = mysql_fetch_field($result)) {
  87. echo "<tr>";
  88. echo "<td> " . $property->name . "</td><br />";
  89. echo " <td>" . $property->table . "</td><br />";
  90. echo " <td>" . $property->def . "</td><br />";
  91. echo " <td>" . $property->max_length . "</td><br />";
  92. echo "<td> " . $property->not_null . "</td><br />";
  93. echo " <td>" . $property->primary_key . "</td><br />";
  94. echo "<td> " . $property->unique_key . "</td><br />";
  95. echo "<td> " . $property->multiple_key . "</td><br />";
  96. echo "<td> " . $property->numeric . "</td><br />";
  97. echo "<td> " . $property->blob . "</td><br />";
  98. echo "<td> " . $property->type . "</td><br />";
  99. echo "<td> " . $property->unsigned . "</td><br />";
  100. echo "<td>" . $property->zerofill . "</td><br />";
  101. echo "</tr>";
  102. }//end while
  103. echo "</table>";
  104. }//end fetch_fiedl function
  105. function mysqli_test(){
  106. $mysql_obj=new mysqli('localhost','root','root','scaffold');
  107. if(mysqli_connect_errno()){
  108. printf("Connect failed: %s\n",mysqli_connect_error());
  109. exit();
  110. }//end if
  111. $query="SELECT * FROM obs_forum_posts";
  112. if($result=$mysql_obj->query($query)){
  113. while ($finfo=$result->fetch_field()){
  114. //get fieldpointer offset
  115. $currentfield=$result->current_field;
  116. printf("Column %d:",$currentfield);
  117. printf("Name: %s<br />",$finfo->name);
  118. }//end while
  119. $result->close();
  120. }// end if
  121. else
  122. {printf("Query faild: %s\n",$mysql_obj->error);}
  123. $mysql_obj->close();
  124. }//end mysqli_test function
  125. function get_colom_names($db,$table){
  126. $obj=new mysqli('localhost','root','root',$db);
  127. if(mysqli_connect_errno()){
  128. printf("Connection faild: %s",$obj->error);
  129. exit();
  130. }//end if
  131. $query="SELECT * FROM $table LIMIT 1";
  132. }//end of function get_colom_names
  133. }//end class
  134. ?>