/scaffold/class.php
PHP | 171 lines | 132 code | 37 blank | 2 comment | 15 complexity | 188497fccdbb91c8571719b443cd50a1 MD5 | raw file
Possible License(s): GPL-2.0, MIT
- <?php
-
- class mysql_funks
- {
- function connect_to_mysql(){
- $link=mysql_connect('localhost','root','root');
- if(!$link){
- die('Connection Faild: '.mysql_error());
- }
- }
-
- function table_field_information($query)
- {
-
- $select_db=mysql_select_db('scaffold');
- if(!$select_db){
- die('Database couldn\'t be selected '.mysql_error());
- }
- $result=mysql_query($query);
- $i=0;
-
- while($i<mysql_num_fields($result)){
- echo "Information for colum $i:<br />\n";
- $meta=mysql_fetch_field($result,$i);
- if(!$meta){
-
- echo "No information available<br />\n";
- }
- echo "<pre>
-
- blob: $meta->blob
- max_length: $meta->max_length
- multiple_key: $meta->multiple_key
- name: $meta->name
- not_null: $meta->not_null
- numeric: $meta->numeric
- primary_key: $meta->primary_key
- table: $meta->table
- type: $meta->type
- default: $meta->def
- unique_key: $meta->unique_key
- unsigned: $meta->unsigned
- zerofill $meta->zerofill
- </pre>";
- $i++;
- }
- mysql_free_result($result);
- }
- // Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead.
- function fetch_object($sql){
-
- $select_db=mysql_select_db('scaffold');
- if(!$select_db){
- die('Database selection faild: '.mysql_error());
- }
- $result=mysql_query("Select * from obs_forum_posts");
- while($row=mysql_fetch_object($result)){
-
- echo $row->id." : " ;
- echo $row->title. "<br />";
-
- }//end while
- mysql_free_result($result);
-
- }//end function
-
- function list_fields_table($db,$tablename){
- $select_db=mysql_select_db($db);
- if(!$select_db){
- die('Table selection faild: '. mysql_error());
- }//end if
-
- $result=mysql_query("SHOW COLUMNS FROM $tablename");
- if(!$result){
-
- die('Could not run query'. mysql_error());
- }//end if
-
- if(mysql_num_rows($result)>0){
-
- while($row=mysql_fetch_assoc($result)){
-
- print_r($row);
-
- }//end while
-
-
- }//end if
- }//end function list_fields_table
-
- function fetch_field(){
-
-
- $db_selected = mysql_select_db("scaffold");
- if(!$db_selected){
- die('Database selection faild'.mysql_error());
- }//end if
-
- $sql = "SELECT * from obs_forum_posts ";
- $result = mysql_query($sql);
- if(!$result){
- die('Query faild due to: '.mysql_error());
- }//end if
- echo "<table>";
- echo "<tr><td><b>Field name:</b></td> <td><b>Table name:</b></td> <td><b>Default value:</b></td>
- <td><b>Max length:</b></td> <td><b>Not NULL:</b></td> <td><b>Primary Key:</b></td> <td><b>Unique Key:</b>
- </td> <td><b>Mutliple Key:</b></td> <td><b>Numeric Field:</b></td> <td><b>BLOB:</b></td> <td><b>Field Type:</b></td>
- <td><b>Unsigned:</b></td> <td><b>Zero-filled: </b></td></tr>";
-
- while ($property = mysql_fetch_field($result)) {
- echo "<tr>";
- echo "<td> " . $property->name . "</td><br />";
- echo " <td>" . $property->table . "</td><br />";
- echo " <td>" . $property->def . "</td><br />";
- echo " <td>" . $property->max_length . "</td><br />";
- echo "<td> " . $property->not_null . "</td><br />";
- echo " <td>" . $property->primary_key . "</td><br />";
- echo "<td> " . $property->unique_key . "</td><br />";
- echo "<td> " . $property->multiple_key . "</td><br />";
- echo "<td> " . $property->numeric . "</td><br />";
- echo "<td> " . $property->blob . "</td><br />";
- echo "<td> " . $property->type . "</td><br />";
- echo "<td> " . $property->unsigned . "</td><br />";
- echo "<td>" . $property->zerofill . "</td><br />";
- echo "</tr>";
- }//end while
-
- echo "</table>";
-
- }//end fetch_fiedl function
-
-
- function mysqli_test(){
- $mysql_obj=new mysqli('localhost','root','root','scaffold');
- if(mysqli_connect_errno()){
- printf("Connect failed: %s\n",mysqli_connect_error());
- exit();
-
- }//end if
-
- $query="SELECT * FROM obs_forum_posts";
- if($result=$mysql_obj->query($query)){
-
- while ($finfo=$result->fetch_field()){
-
- //get fieldpointer offset
- $currentfield=$result->current_field;
- printf("Column %d:",$currentfield);
- printf("Name: %s<br />",$finfo->name);
-
- }//end while
- $result->close();
- }// end if
- else
- {printf("Query faild: %s\n",$mysql_obj->error);}
- $mysql_obj->close();
- }//end mysqli_test function
-
- function get_colom_names($db,$table){
- $obj=new mysqli('localhost','root','root',$db);
- if(mysqli_connect_errno()){
- printf("Connection faild: %s",$obj->error);
- exit();
- }//end if
- $query="SELECT * FROM $table LIMIT 1";
-
-
- }//end of function get_colom_names
-
- }//end class
- ?>