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. Quote Link to comment 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' Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 />"; } } } Quote Link to comment Share on other sites More sharing options...
malikah Posted August 11, 2009 Author Share Posted August 11, 2009 bump... Quote Link to comment Share on other sites More sharing options...
malikah Posted August 12, 2009 Author Share Posted August 12, 2009 bump... Quote Link to comment Share on other sites More sharing options...
malikah Posted August 12, 2009 Author Share Posted August 12, 2009 bump... Quote Link to comment Share on other sites More sharing options...
malikah Posted August 12, 2009 Author Share Posted August 12, 2009 sigh... bump... Quote Link to comment 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...) Quote Link to comment Share on other sites More sharing options...
malikah Posted August 13, 2009 Author Share Posted August 13, 2009 bump... Quote Link to comment Share on other sites More sharing options...
trq Posted August 13, 2009 Share Posted August 13, 2009 What database access object are you using? Quote Link to comment 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); } Quote Link to comment Share on other sites More sharing options...
malikah Posted August 13, 2009 Author Share Posted August 13, 2009 bump... Quote Link to comment Share on other sites More sharing options...
trq Posted August 14, 2009 Share Posted August 14, 2009 Take a look at example #1 here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.