23.12.2012 Posted January 28, 2010 Share Posted January 28, 2010 Today, I came across this error Catchable fatal error: Object of class mysqli_result could not be converted to string in /Library/WebServer/Documents/sangym2/functions/user_title.php on line 12 What I'm trying to do is perform a query inside a function, in order to get the name field using the provided id. As far as I've read, the issue is triggered by the mysqli_query() function, which does not return a string, so the result of the function cannot be echo-ed. So how can I convert it to string before I display it? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 28, 2010 Share Posted January 28, 2010 Check the examples, comments, and references on the documentation page for mysqli_query, there are several different functions you can use to get the results from the resource. Link to comment Share on other sites More sharing options...
Redroest Posted January 28, 2010 Share Posted January 28, 2010 The best way to do this is by making the mysqli as a class: <?php//Database connection$db = array ( 'host' => $db_host, 'user' => $db_user, 'pass' => $db_pass, 'dbname' => $db_name);$mysqli = new mysqli($db['host'], $db['user'], $db['pass'], $db['dbname']);if(mysqli_connect_errno()){ trigger_error('Fout bij verbinding: '.$mysqli->error);}//Sample query (SELECT) $sql = "SELECT * FROM testtable WHERE tester='test'"; if(!$test= $mysqli->query($sql)) { trigger_error('Fout in query: '.$mysqli->error); } else { while($testinfo= $test->fetch_assoc()) { echo $testinfo['test_name'].'<br />'; }}?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.