malikah Posted August 10, 2009 Share Posted August 10, 2009 Hi, I'm trying to return the name of each column in a MySQL database using PREPARED statements only. Cheers. Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/ Share on other sites More sharing options...
taquitosensei Posted August 11, 2009 Share Posted August 11, 2009 you can query the information_schema for your table SELECT * FROM information_schema.COLUMNS where table_name='yourtablename' Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-895745 Share on other sites More sharing options...
cunoodle2 Posted August 11, 2009 Share Posted August 11, 2009 Write the queries in standard mysql statements and I will help you convert to prepared statements. Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-895748 Share on other sites More sharing options...
taquitosensei Posted August 11, 2009 Share Posted August 11, 2009 I'm retarded and didn't see the PREPARED in bold. Ignore my post. Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-895786 Share on other sites More sharing options...
malikah Posted August 11, 2009 Author Share Posted August 11, 2009 Write the queries in standard mysql statements and I will help you convert to prepared statements. This worked for me procedurally: $query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS where table_name='table'"; if(mysqli_real_query($dblink, $query)) { $result = mysqli_store_result($dblink); while($row = mysqli_fetch_assoc($result)) { foreach($row as $_colName => $_colValue) { echo "{$_colValue}<br />"; } } } Unfortunately, I can't figure out the object-oriented equivalent. Here's my attempt: $query = "SELECT COLUMN_NAME FROM information_schema.COLUMNS where table_name='table'"; if($stmt = $this->conn->prepare($query)) { $stmt->execute(); $stmt->store_result(); while($row = $stmt->fetch()) { foreach($row as $_colName => $_colValue) { echo "{$_colValue}<br />"; } } } Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-895804 Share on other sites More sharing options...
malikah Posted August 11, 2009 Author Share Posted August 11, 2009 bump... Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-895890 Share on other sites More sharing options...
malikah Posted August 12, 2009 Author Share Posted August 12, 2009 bump... Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-896323 Share on other sites More sharing options...
malikah Posted August 12, 2009 Author Share Posted August 12, 2009 bump... Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-896455 Share on other sites More sharing options...
malikah Posted August 12, 2009 Author Share Posted August 12, 2009 sigh... bump... Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-896597 Share on other sites More sharing options...
malikah Posted August 12, 2009 Author Share Posted August 12, 2009 bump... (25 hours and 10 minutes later...) Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-896723 Share on other sites More sharing options...
malikah Posted August 13, 2009 Author Share Posted August 13, 2009 bump... Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-897262 Share on other sites More sharing options...
trq Posted August 13, 2009 Share Posted August 13, 2009 What database access object are you using? Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-897266 Share on other sites More sharing options...
malikah Posted August 13, 2009 Author Share Posted August 13, 2009 What database access object are you using? You mean this? $private $conn; function __construct() { $this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME); } Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-897305 Share on other sites More sharing options...
malikah Posted August 13, 2009 Author Share Posted August 13, 2009 bump... Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-897558 Share on other sites More sharing options...
trq Posted August 14, 2009 Share Posted August 14, 2009 Take a look at example #1 here. Link to comment https://forums.phpfreaks.com/topic/169635-return-the-name-of-each-column-in-mysql-database/#findComment-897968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.