mrbuzz Posted April 10, 2009 Share Posted April 10, 2009 Hi there, I'm new to PHP - normally an ASP guy but trying to get something setup in php for a change. We're running a Windows 2003 Server with PHP & MySql installed. I know PHP works (phpinfo()) and I know MySql works (use it for all the .asp apps) and phpmyadmin works, however whenever trying to display query results from our own pages we are greeted with blank pages. Please see below, hope you can help! When running this code we get a blank page, no errors or anything // Connect to the DB $link = mysqli_connect("IPAddress", "User", "Password", "dbname"); // Note the fields above are populated correctly usually, but filtered for this forum post. /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* Create table doesn't return a resultset */ if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) { printf("Table myCity successfully created.\n"); } /* Select queries return a resultset */ if ($result = mysqli_query($link, "SELECT Name FROM City LIMIT 10")) { printf("Select returned %d rows.\n", mysqli_num_rows($result)); /* free result set */ mysqli_free_result($result); } /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */ if ($result = mysqli_query($link, "SELECT * FROM City", MYSQLI_USE_RESULT)) { /* Note, that we can't execute any functions which interact with the server until result set was closed. All calls will return an 'out of sync' error */ if (!mysqli_query($link, "SET @a:='this will not work'")) { printf("Error: %s\n", mysqli_error($link)); } mysqli_free_result($result); } mysqli_close($link); However when running <?php // Connect to the DB if(!$db=mysqli_connect("ipaddress", "user", "password", "dbname")){ throw new Exception('Error connecting to host.'.mysqli_connect_error()); } // display host information echo 'Host information: '.mysqli_get_host_info($db); echo '<br/>hello'; // close connection mysqli_close($db); ?> I get shown the Host information just fine. If I add to that code, at the bottom, then I don't see this second "Hello". $result=$mysqli->query('SELECT * FROM customer'); echo '<br/>hello'; Any idea what could be causing this? and how to solve. Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/ Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 Without examining your code I can tell you the most of the time a blank page usually refers to a fatal syntactical error that's being suppressed. After your first opening <?php tag add these lines: ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806374 Share on other sites More sharing options...
mrbuzz Posted April 10, 2009 Author Share Posted April 10, 2009 Same situation even after adding that for the first code block I posted (which it should be noted I got from http://ie2.php.net/manual/en/mysqli.query.php - simply to test things were working!) The second block did return an error but then that was as you said an error on my part. PS - You can see the results of the phpinfo page here http://78.129.162.2/phptest.php - does it look ok? Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806381 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 You should be learning php, developing php code, and debugging php code on a system where error_reporting is set to E_ALL and display_errors is set to ON in your php.ini (stop and start your web server to get changes made to php.ini to take effect.) Fatal parse errors are not displayed when those two settings are made in a script because the script never executes. Your mysql extension is probably not enabled, giving a fatal runtime error. But find out for sure by turning on full php error reporting/display errors in php.ini (or a .htaccess file - Apache, or in a local php.ini - php running as a CGI application.) Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806384 Share on other sites More sharing options...
mrbuzz Posted April 10, 2009 Author Share Posted April 10, 2009 thanks for help so far guys, have turned on those settings in php.ini as requested, same situation for me though - blank pages. Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806395 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 Can you post the code for the entire page that shows a blank page? Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806400 Share on other sites More sharing options...
mrbuzz Posted April 10, 2009 Author Share Posted April 10, 2009 Certainly can... please see below <?php $mysqli = new mysqli("IP", "root", "PWD", "DBNAME"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* Create table doesn't return a resultset */ if ($mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) { printf("Table myCity successfully created.\n"); } /* Select queries return a resultset */ if ($result = $mysqli->query("SELECT Name FROM City LIMIT 10")) { printf("Select returned %d rows.\n", $result->num_rows); /* free result set */ $result->close(); } /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */ if ($result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT)) { /* Note, that we can't execute any functions which interact with the server until result set was closed. All calls will return an 'out of sync' error */ if (!$mysqli->query("SET @a:='this will not work'")) { printf("Error: %s\n", $mysqli->error); } $result->close(); } $mysqli->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806403 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 thanks for help so far guys, have turned on those settings in php.ini as requested, same situation for me though - blank pages. So, did you stop and start your web server to get any change made to php.ini to take effect, is the php.ini that you are changing the one that php is using, and did you use a phpinfo() statement to confirm that the settings are being used? Also, how did you obtain php, the .msi installer or the .zip package? Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806407 Share on other sites More sharing options...
mrbuzz Posted April 10, 2009 Author Share Posted April 10, 2009 I did stop/start yes and the phpinfo showed the changes made. (you can see the phpinfo page here http://78.129.162.2/phptest.php) Am not sure what was used to install, someone did it for me when I brought the server. I've just had a look in the Administrator users documents and there is both a 5.2.5 zip and an .msi file there though! Is there anyway I can find out short of asking them (they wont be in again til Tuesday) Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806412 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 I looked at your phpinfo() link. Php 5.2.4 or 5.2.5 (I don't remember which) introduced a serious bug when output buffering is on in php.ini. Fatal errors are not reported because the stupid programmer that added a feature forgot to call the code to flush the output buffer when a fatal error stops execution. You should upgrade to the latest php version or at a minimum turn off output buffering in php.ini. Edit: And your page might be blank because the code is taking an execution path that is not outputting anything. Edit2: I just checked and the bug I mentioned was in php 5.2.4 and was corrected in 5.2.5. Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806418 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 As to the .msi installer, I have no proof (and I'm not about to screw up my system by using the .msi installer as a test), but it seems like it puts settings into the Windows registry that override php.ini settings and the phpinfo() shows what the php.ini settings are and not the actual settings. Edit: If you go into the Windows control panel and there is an add/remove item for php, it means that php was installed using the .msi installer. If that is the case, you must use the add/remove item to enable extensions, like mysqli. Otherwise they won't actually get enabled. Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806432 Share on other sites More sharing options...
mrbuzz Posted April 10, 2009 Author Share Posted April 10, 2009 cheers for all the help, have gone into CP but nothing in there, so presume was installed via the .zip package. We're getting somewhere though, looked at what I'd got off that site and yes there were no else statements so added some in and it posts the error for everything except the initial connection. So, for some reason then I can connect but beyond that can't do anything... is there a common reason for this? Is the code i've got off that site simply wrong for calling from a table? I'm now using the below... I know I have read/write permission on the DB as I'm logging in as root <?php $mysqli = new mysqli("ip", "root", "pwd", "dbname"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* Create table doesn't return a resultset */ if ($mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) { printf("Table myCity successfully created.\n"); } else { print "Error 1"; } /* Select queries return a resultset */ if ($result = $mysqli->query("SELECT Name FROM City LIMIT 10")) { printf("Select returned %d rows.\n", $result->num_rows); /* free result set */ $result->close(); } else { print "Error 2"; } /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */ if ($result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT)) { /* Note, that we can't execute any functions which interact with the server until result set was closed. All calls will return an 'out of sync' error */ if (!$mysqli->query("SET @a:='this will not work'")) { printf("Error: %s\n", $mysqli->error); } $result->close(); } else { print "Error 3"; } $mysqli->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806492 Share on other sites More sharing options...
mrbuzz Posted April 10, 2009 Author Share Posted April 10, 2009 ok to update got it working - thank you to PFMaBiSmAd for pointing out the lack of Else statements, got me on the right path. After that I could see the mysql errors that the insert statement was wrong, so I changed it to one which worked, as a result the select then worked etc etc Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806513 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 Insert, where? Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806517 Share on other sites More sharing options...
mrbuzz Posted April 10, 2009 Author Share Posted April 10, 2009 Insert, where? Sorry, meant Create, not insert. The create statement kept giving errors so changed it to a simple "CREATE TABLE newtable (sId INT)" statement instead Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806525 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2009 Share Posted April 10, 2009 Just a side note, most if() conditional tests need an else statement to do something when the test fails, even if it is just to output a meaningful user message that the code could not complete its designed task. Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806535 Share on other sites More sharing options...
mrbuzz Posted April 10, 2009 Author Share Posted April 10, 2009 Cheers, all working now - succesfully generating invoices in pdf format now How do I mark the thread as solved? Can't find the option Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806792 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 Bottom right tab, looks like [sOLVED]. Quote Link to comment https://forums.phpfreaks.com/topic/153477-solved-problems-executing-queries-returns-blank-page/#findComment-806846 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.