- rafaelbernard / driver_pgsql.php
- Mysql show all columns in table code example
- Display all columns in a grid in php MySql
- How can we list all the columns of a MySQL view as we can list the columns of a MySQL table?
- Syntax
- Example
- How to display some columns (not all) in MySQL?
- Show MySQL tables, column names, types and more with PHP
- $table
- Php $SQL = "SHOW FULL COLUMNS FROM ".$_REQUEST["table"]." LIKE '".mysql_field_name($rs,$i)."'";
- Examples
- Related
rafaelbernard / driver_pgsql.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
# at pg4wp_rewrite |
# right after `Fix tables listing` |
// Rewriting SHOW FULL COLUMN |
elseif( 0 === strpos( $ sql , ‘SHOW FULL COLUMN’ )) |
$ logto = ‘SHOWFULL’ ; |
$ sql = str_replace( ‘SHOW FULL COLUMNS FROM ‘ , ‘SELECT column_name FROM information_schema.columns WHERE table_name = ‘ , $ sql ); |
$ sql = str_replace( ‘`’ , » ‘ «, $ sql ); |
> |
HI i am checking the comment on plugin page, thanks for that,
i am also trying to install wordpress along with the postgresql
I dont the below checklists
1.g4wp directory in your /wp-content
2.Copy the db.php from the pg4wp directory to wp-content
3.in wp-setting added username and pass and dbname of postgresql
but it not worked for
tail -f /var/log/nginx/error.log
#2 /var/www/html/wp-includes/option.php(184): wpdb2->get_results(‘SELECT option_n. ‘)
#3 /var/www/html/wp-includes/functions.php(1372): wp_load_alloptions()
#4 /var/www/html/wp-includes/load.php(532): is_blog_installed()
#5 /var/www/html/wp-settings.php(133): wp_not_installed()
#6 /var/www/html/wp-config.php(89): require_once(‘/var/www/html/w. ‘)
#7 /var/www/html/wp-load.php(39): require_once(‘/var/www/html/w. ‘)
#8 /var/www/html/wp-blog-header.php(13): require_once(‘/var/www/html/w. ‘)
#9 /var/www/html/index.php(17): require(‘/var/www/html/w. ‘)
#10
thrown in /var/www/html/wp-content/pg4wp/core.php(32) : eval()’d code on line 1637″ while reading response header from upstream, client: 111.92.88.37, server: rakesh.com, request: «GET / HTTP/1.1», upstream: «fastcgi://unix:/run/php/php7.0-fpm.sock:», host: «rakesh.com»
Mysql show all columns in table code example
Deprecation note As we know that views are a type of virtual tables and are the composition of tables too hence we can use the same query to list all the columns of a MySQL view as we can list the columns of a MySQL table. Example Suppose if we want to get a list of columns of a view named ‘Info’ then it can be done with the help, of the following query −
Display all columns in a grid in php MySql
If you want the column names of a table from a query, you can do something like this:
$c=0; $myarray = array(); while ($c < mysql_num_fields($result)) < # Get field name $fld = mysql_fetch_field($result, $c); # Put field name in array $myarray[] = $fld->name; # Count + 1 for next field $c++; > echo "\n"; echo "\n"; echo "\n"; foreach($myarray as $columnheading) < echo "".$columnheading." \n"; > echo " \n"; echo "\n"; echo "\n"; if (mysql_num_rows($result) > 0) < while ($row = mysql_fetch_assoc($result)) < echo "\n"; foreach($row as $td) < echo "".$td." "; > echo " \n"; > > echo "\n"; echo "
";
You have the column names in a array. Add print_r($myarray) to see what columns are generated.
EDIT: added full example.
According to PHP documentation here
$result = mysql_query("SHOW COLUMNS FROM sometable"); if (!$result) < echo 'Could not run query: ' . mysql_error(); exit; >if (mysql_num_rows($result) > 0) < while ($row = mysql_fetch_assoc($result)) < print_r($row); >>
@Joey has written an excellent answer, just wanted to add that, mysql_num_fields() function has been deprecated since PHP 7.0 and
should be used in it’s stead. Deprecation note
MySQL Show Columns, We first launch the tool and log in with the username and password to display the given table’s column information in MySQL Workbench. Now, we need to do the following steps to show the column information: 1. Go to the Navigation tab and click on the Schema menu where all the previously created databases available.
How can we list all the columns of a MySQL view as we can list the columns of a MySQL table?
As we know that views are a type of virtual tables and are the composition of tables too hence we can use the same query to list all the columns of a MySQL view as we can list the columns of a MySQL table. In other words, we can use SHOW FULL COLUMNS statement to get the structure of a MySQL view. Its syntax would be as follows −
Syntax
SHOW FULL COLUMNS FROM View_name;
Here view_name is the name of the view from which we want to get the list of columns.
Example
Suppose if we want to get a list of columns of a view named ‘Info’ then it can be done with the help, of the following query −
mysql> SHOW FULL COLUMNS FROM INFO\G *************************** 1. row *************************** Field: ID Type: int(11) Collation: NULL Null: YES Key: Default: NULL Extra: Privileges: select,insert,update,references Comment: *************************** 2. row *************************** Field: NAME Type: varchar(20) Collation: latin1_swedish_ci Null: YES Key: Default: NULL Extra: Privileges: select,insert,update,references Comment: *************************** 3. row *************************** Field: SUBJECT Type: varchar(20) Collation: latin1_swedish_ci Null: YES Key: Default: NULL Extra: Privileges: select,insert,update,references Comment: *************************** 4. row *************************** Field: ADDRESS Type: varchar(20) Collation: latin1_swedish_ci Null: YES Key: Default: NULL Extra: Privileges: select,insert,update,references Comment: 4 rows in set (0.00 sec)
Show table columns mysql command line Code Example, show table columns mysql command line Code Example All Languages >> SQL >> show table columns mysql command line “show table columns mysql command line” Code Answer’s show table columns mysql command line sql by ama-lion on Apr 21 2021 Donate Comment 2 xxxxxxxxxx 1 SHOW COLUMNS from tablename; …
How to display some columns (not all) in MySQL?
In order to show some columns, use NOT IN and set those columns which you do not want to display. Let us first create a table. Following is the query −
mysql> create table student_Information -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(50), -> StudentAge int, -> StudentAddress varchar(100), -> StudentAllSubjectScore int -> ); Query OK, 0 rows affected (0.69 sec)
Following is the query to display a description about the above table −
mysql> desc student_Information;
This will produce the following output −
+------------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------------+--------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(50) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | | StudentAddress | varchar(100) | YES | | NULL | | | StudentAllSubjectScore | int(11) | YES | | NULL | | +------------------------+--------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec)
Following is the query to display only some columns −
mysql> SHOW COLUMNS FROM student_Information where field not in('StudentAddress','StudentAllSubjectScore');
This will produce the following output −
+-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(50) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
Show columns from all tables Code Example, “show columns from all tables” Code Answer’s. show table columns . sql by Sore Snail on May 11 2021 Donate Comment Sore …
Show MySQL tables, column names, types and more with PHP
Showing a MySQL database tables with their columns, type, keys and more is done using the MySQL SHOW syntax. For the tables SHOW TABLES is used whilst to get the details about the columns for individual tables SHOW COLUMNS.
First step is creating the PDO MySQL connection and then defining the database that the information will be retrieved from
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $database = 'users';//Database $show_tables = $db->prepare("SHOW TABLES;"); $show_tables->execute(); while ($data = $show_tables->fetch(PDO::FETCH_ASSOC)) < $table = $data["Tables_in_$database"];//Table name .
This will loop through all the tables in the database user
Next another query gets built into this loop that goes through each of the tables getting the column names, types, keys, defaults and more
prepare("SHOW COLUMNS FROM $table;"); $show_cols->execute(); while ($col = $show_cols->fetch(PDO::FETCH_ASSOC)) < $name = $col['Field']; .
View what gets returned from the show columns command here.
Finally getting creating an output and making its readability somewhat decent can be seen like this WordPress database with the full code below the image;
body < background-color: #313233; color: #e2e3e5; font-family: Verdana, Geneva, sans-serif; font-size: 0.95rem; >.table-name < font-size: 1.2rem; margin-bottom: 0.3rem; >.db-table < margin-left: 0.5rem; >.type < color: #abccff; >.null < color: #ffb0a5; font-style: italic; >.key < color: #dcffac; >.default < color: #9cffeb; >.extra setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $database = 'users';//Set database name here $show_tables = $db->prepare("SHOW TABLES;"); $show_tables->execute(); while ($data = $show_tables->fetch(PDO::FETCH_ASSOC)) < $table = $data["Tables_in_$database"]; echo "$table
"; $show_cols = $db->prepare("SHOW COLUMNS FROM $table;"); $show_cols->execute(); while ($col = $show_cols->fetch(PDO::FETCH_ASSOC)) < if ($col['Null'] == 'YES') < $is_null = 'Is NULL'; >else < $is_null = 'Not NULL'; >$key = $col['Key']; if ($key == 'PRI') < $key_type = 'Primary key'; >elseif ($key == 'UNI') < $key_type = 'Unique key'; >elseif ($key == 'MUL') < $key_type = 'Multi key'; >else < $key_type = '';//No key >echo "" . $col['Field'] . " " . $col['Type'] . " $is_null $key_type " . $col['Default'] . " " . $col['Extra'] . ""; > > ?>
Php $SQL = "SHOW FULL COLUMNS FROM ".$_REQUEST["table"]." LIKE '".mysql_field_name($rs,$i)."'";
This tutorials show you how to use mysql_field_name.
mysql_field_name is used in the following way.
$SQL = "SHOW FULL COLUMNS FROM ".$_REQUEST["table"]." LIKE '".mysql_field_name($rs,$i)."'"; This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide. Alternatives to this function include:
The mysql_field_name is declared as follows:
mysql_field_name( resource $result, int $field_offset): string|false
The return value is The name of the specified field index on success or false on failure.
Examples
/* w w w . d e m o 2 s . c o m */ include "./Global/MySQL.php"; if($_REQUEST["GetFields"]=="TRUE") < $SQL = "SELECT * FROM ".$_REQUEST["table"]." LIMIT 1"; //print $SQL; $rs = mysql_query($SQL); $rows = array(); for($i=0; $i $SQL = "SHOW FULL COLUMNS FROM ".$_REQUEST["table"]." LIKE '".mysql_field_name($rs,$i)."'"; $rsf = mysql_query($SQL); $r = mysql_fetch_assoc($rsf); $type = explode(' ',$r["Type"]); $name = mysql_field_name($rs, $i); $len = mysql_field_len($rs, $i); $flagsString = mysql_field_flags($rs, $i); $flags = mysql_fetch_field($rs,$i); //print "
".$flagsString."".print_r($flags,true)."";
$rows[] = array( 'key'=>$flags->primary_key, 'name'=>$r["Field"], 'OrgName'=>$r["Field"], 'DataType'=>$type[0], 'NotNULL'=>$flags->not_null, 'AutoInc'=>(stristr($flagsString,"auto_increment")===FALSE?'0':'1'), 'Unsigned'=>$flags->unsigned, 'Binary'=>(stristr($flagsString,"binary")===FALSE?'0':'1'), 'Zerofill'=>$flags->zerofill, 'Default'=>empty($r["Default"])?'':$r["Default"], 'Comment'=>empty($r["Comment"])?'':$r["Comment"] ); > $SQL = "SHOW INDEX FROM ".$_REQUEST["table"]; $rs = mysql_query($SQL); $primary = array(); while($r=mysql_fetch_assoc($rs)) < if($r["Key_name"]=="PRIMARY") $primary[] = $r["Column_name"]; > $dbtable = explode(".",$_REQUEST["table"]); $SQL = "SHOW TABLE STATUS FROM ".$dbtable[0]." LIKE '".$dbtable[1]."'"; $rs = mysql_query($SQL); $r = mysql_fetch_assoc($rs); print '.json_encode($dbtable[0]).',table:'.json_encode($dbtable[1]).',comment:'.json_encode($r["Comment"]).',engine:'.json_encode($r["Engine"]).',primary:'.json_encode($primary).',rows:'.json_encode($rows).'>'; // exit(); > if(!empty($_REQUEST["node"]) && $_REQUEST["node"]!='0') < if(stristr($_REQUEST["node"],"__ROOT__.")===FALSE) < $SQL = "DESC ".$_REQUEST["node"]; $rs = mysql_query($SQL); $a = array(); while($r=mysql_fetch_assoc($rs)) < $f = array("name"=>$r["Field"], "id"=>($_REQUEST["node"].".".$r["Field"]), "leaf"=>true,"icon"=>"./images/rombus.png"); if($r["Key"]=="PRI") $f["icon"]="./images/key.png"; $a[] = $f; > print '.json_encode($a).'>'; exit(); > $_REQUEST["node"] = str_replace("__ROOT__.","",$_REQUEST["node"]); $SQL = "SHOW TABLES FROM ".mysql_real_escape_string($_REQUEST["node"]); $rs = mysql_query($SQL); $a = array(); while($r=mysql_fetch_row($rs)) < $a[] = array("name"=>$r[0], "id"=>($_REQUEST["node"].".".$r[0]), "leaf"=>false,"icon"=>"./images/table.png"); > print '.json_encode($a).'>'; exit(); > $SQL = "SHOW DATABASES"; $rs = @mysql_query($SQL); $a = array(); while($r=@mysql_fetch_row($rs)) < $a[] = array("name"=>$r[0], "id"=>("__ROOT__.".$r[0]),"icon"=>"./images/database.png"); > print '.json_encode($a).'>'; ?>Related
- Php return mysql_field_len($result, $i);
- PHP m Usage mysql_field_name
- Php $FieldNames[]=mysql_field_name($result, $i);
- Php $SQL = "SHOW FULL COLUMNS FROM ".$_REQUEST["table"]." LIKE '".mysql_field_name($rs,$i)."'";
- Php $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
- Php $columns[$j] = mysql_field_name($r, $j);
- Php $field = mysql_field_name($struktur,0);
demo2s.com | Email: | Demo Source and Support. All rights reserved.