BrainPill Posted January 26, 2019 Share Posted January 26, 2019 I would like to fit this specific mysl query into php. I use prepared statements OOP for most queries if possible. Is there a way to get this executed: // database connection $sql = 'SELECT Table_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = `my_database` AND COLUMN_NAME LIKE `my_column` '; // do OOP prepared statements to get the columns I tried the mysql code in phpmyadmin and it worked properly, but in PHP no output. Please help. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 28, 2019 Share Posted January 28, 2019 You need to check for errors in PHP to see what the issue is. Maybe your database user doesn't have access to information_schema. Link to comment Share on other sites More sharing options...
BrainPill Posted January 30, 2019 Author Share Posted January 30, 2019 PHP does not give any errors. Or can I see it in phpmyadmin? This is the intended php/mysql code from the function I made. <?php // make OOP mysqli database connection $sql = 'SELECT Table_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = `yourdatabase_db` AND COLUMN_NAME LIKE `user_id` '; $stmt = $conn->prepare($sql) ; var_dump($stmt); $stmt->execute(); var_dump($stmt); //$stmt->bind_result($tabs); while ($stmt->fetch()) { var_dump($tabs); } printf("Error: %s.\n\r", mysqli_stmt_error($stmt)); printf("Error: %d.\n\r", mysqli_stmt_errno($stmt)); printf("Error: %s.\n\r", mysqli_stmt_sqlstate($stmt)); ?> Link to comment Share on other sites More sharing options...
justsomeguy Posted January 30, 2019 Share Posted January 30, 2019 If you're not seeing error messages with that then there's a problem, because that query has errors. I would suggest picking either object-oriented or procedural and stick with it, don't mix them. mysqli_stmt_error expects a statement identifier returned from mysqli_stmt_init, not a mysqli_stmt object. There is a different way to get error information from a mysqli_stmt object, so start with the documentation and go from there. Link to comment Share on other sites More sharing options...
Funce Posted January 30, 2019 Share Posted January 30, 2019 (edited) 6 hours ago, justsomeguy said: mysqli_stmt_error expects a statement identifier returned from mysqli_stmt_init, not a mysqli_stmt object. Apologies for the interjection, this isn't exactly correct, both procedural and OO Style use objects as parameters and returns. (mysqli_stmt_init returns a mysqli_stmt object) But the advice is still valid, try not to mix them. Edited January 30, 2019 by Funce Link to comment Share on other sites More sharing options...
justsomeguy Posted January 31, 2019 Share Posted January 31, 2019 It looks like that's correct, the documentation isn't very clear on that: Parameters ¶ stmt Procedural style only: A statement identifier returned by mysqli_stmt_init(). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now