Posts

Showing posts with the label mysqli

SQL Query not updating the database

SQL Query not updating the database I was getting an error from my processing form down below. I'm not sure why it isn't updating to the database when I hit submit. It says it has been successful but yet the databse has not been updated?! I think it maybe because of the "mysqli_stmt_execute" but I'm not sure. Any thoughts :/ Thanks. <?php if(isset($_POST['submit'])){ include_once 'connection.php'; $first = mysqli_real_escape_string($conn, $_POST['first']); $last = mysqli_real_escape_string($conn, $_POST['last']); $uid = mysqli_real_escape_string($conn, $_POST['uid']); $pwd = mysqli_real_escape_string($conn, $_POST['pwd']); $hashedPwd = md5($pwd); //Error Handling //Checking for empty fields if(empty($first) || empty($last) || empty($uid) || empty($pwd)){ header("Location: ../signup.php?signup=empty"); exit(); }else{ //Checking if the input...

Optimizing mysqli query for calculating Median using GROUP BY & ORDER BY

Optimizing mysqli query for calculating Median using GROUP BY & ORDER BY Please see below for a sample portion of my MySQL table: table name: eb_tickets I want to output the response like so, calculating the median value with distinct values ASC: Currently I am achieving this with the following query: Unfortunately this query is taking around 1 second per record, and I am querying thousands of records with the possibility of 20 different values for the ticket_type column. I am asking for help in seeing if it is possible to optimize my current query in attempt to make the query perform faster. Thank you for your help! 1 Answer 1 Could you try like this ? SELECT counter.ticket_type,AVG(time_first_response) AS median FROM ( SELECT IF(@type = type, @ctr := @ctr + 1, @ctr := 1) AS rownum, @type := ticket_type AS ticket_type, time_first_response FROM eb_tickets ORDER BY...

Calling function from while loop causing infinite loop

Calling function from while loop causing infinite loop I have a MySQLi statement in a function as follows: function getTimeData($time) { $con = mysqli_connect("domain:port", "user", "password", "dbname") or die (mysql_error()); $selectedDate = $_SESSION['date']; $prepTimeData = mysqli_prepare($con, "SELECT * FROM `time` WHERE `date`=? AND `time`<=? AND `endTime`>=?"); $prepTimeData->bind_param("sss", $selectedDate, $time, $time); $prepTimeData->execute(); $getTimeData = $prepTimeData->get_result(); return $getTimeData; } and then a while loop to iterate over all the results: while ($data0800 = getTimeData("0800")->fetch_assoc()) { ?><tr><td><?php $data0800['first_name'];?></td> <td><?php $data0800['riderage'];?></td> <td><?php $data0800['ridinglevel'];?></td> <td><?ph...

wordpress-develop unit testing couldn't fetch mysqli

wordpress-develop unit testing couldn't fetch mysqli I've seen a lot of mysqli errors on stack overflow, but none seem to relate to wordpress-develop I set up the test folder, bootstrap.php. if ( function_exists( 'xdebug_disable' ) ) { xdebug_disable(); } if ( false !== getenv( 'WP_DEVELOP_DIR' ) ) { require getenv( 'WP_DEVELOP_DIR' ) . 'testsphpunitincludesbootstrap.php'; } if ( false !== getenv( 'WP_PLUGIN_DIR' ) ) { define( 'WP_PLUGIN_DIR', getenv( 'WP_PLUGIN_DIR' ) ); } phpunit.xml <phpunit bootstrap="tests/bootstrap.php"> <testsuites> <testsuite> <directory prefix="test-" suffix=".php">./tests/</directory> </testsuite> </testsuites> </phpunit> config define( 'DB_NAME', 'bitnami_wordpress_testing' ); define( 'DB_USER', 'root' ); define( 'DB_PASSWORD', '' ); de...