budimir Posted February 2, 2015 Share Posted February 2, 2015 I'm rewriting my aplication to work with mysqli and one function that I have created is not working anymore. I don't know why connection to db is not working anymore. It worked on mysql. Can you see what is the problem? function zamjena_broja($kataloski_broj){ global $conn_mysqli; $kataloski_broj_data = array(); //Traženje zamjenskog broja $upit_zamjena = "SELECT pocetni_broj, zamjenski_broj, glavni_broj FROM zamjene_brojeva WHERE glavni_broj = '$kataloski_broj' OR pocetni_broj = '$kataloski_broj'"; $rezultat_zamjena = mysqli_query($conn_mysqli, $upit_zamjena) or die (mysqli_error($conn_mysqli)); while($row = mysqli_fetch_array($rezultat_zamjena)){ $kataloski_broj_data[] = $row["zamjenski_broj"]; $kataloski_broj_data[] = $row["pocetni_broj"]; } $kataloski_broj = array_map("unserialize", array_unique(array_map("serialize", $kataloski_broj_data))); //var_dump($kataloski_broj); return $kataloski_broj; } My connection: <?php //Veza na bazu - mysqli protokol $DBServer = 'localhost'; // e.g 'localhost' or '192.168.1.100' $DBUser = 'xxxx'; $DBPass = 'xxxx'; $DBName = 'xxxdb'; $conn_mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName); global $conn_mysqli; // check connection if ($conn_mysqli->connect_error) { trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); } ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 2, 2015 Share Posted February 2, 2015 Are you getting any errors? Is PHP set up to show all errors and warnings? Quote Link to comment Share on other sites More sharing options...
budimir Posted February 2, 2015 Author Share Posted February 2, 2015 No errors! I have error_reporting(E_ALL) and nothing is reported. That's why I don't know what is wrong. Select query is OK, but mysqli_query is not retrieveing any information Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 2, 2015 Share Posted February 2, 2015 Do you know if the errors are being displayed? More information can be seen in example 1 here: http://php.net/manual/en/function.ini-set.php Quote Link to comment Share on other sites More sharing options...
budimir Posted February 3, 2015 Author Share Posted February 3, 2015 No error message. This is what I use: error_reporting(E_ALL); ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); Quote Link to comment Share on other sites More sharing options...
budimir Posted February 3, 2015 Author Share Posted February 3, 2015 OK, so I'm sure problem is with mysqli. When I use same function with mysql it works. Why is it that mysqli_query is not trigering inside that function??? That's a complete mistery for me. It's not even reporting any error messages. Quote Link to comment Share on other sites More sharing options...
Solution tryingtolearn Posted February 3, 2015 Solution Share Posted February 3, 2015 The function works when I test it so the only thing we dont see is how you are calling the function Are you getting anything with //var_dump($kataloski_broj); un commented ? at least array(0){} or something like that? Quote Link to comment Share on other sites More sharing options...
budimir Posted February 3, 2015 Author Share Posted February 3, 2015 I think I finally got it working. One of the problems I found a case where function couldn't return any data. Second thing is that the global connection wasn't setup properly for some reason. I don't understand why no error messages came up. Anyways, now it's working. Thank you for all you're help! Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 3, 2015 Share Posted February 3, 2015 if you are seeing no errors, it could be because you are doing a redirect on the page and you have php's output_buffing on, either in your code or in your php.ini and any error output was discarded due to the buffing/redirect. also, the global $conn_mysqli; statement, where you are making the database connection at, doesn't do anything (well it does, by wasting your time typing that and wasting some time when the code runs.) the only place the global keyword does anything is inside of a function definition, and even there you should not use it, since it breaks the black-box model for function definitions. you should pass ALL external values into functions as call-time parameters. 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.