mysqli

Converting mysql to mysqli - how to get superglobal connection object?

I am trying to convert code from mysql to mysqli. The code uses a single mysql_connect in a file which is included by every other file. mysql_connect returns a MySQL link identifier that is a superglobal so you can rely on having a database connection available in any of your own functions. It looks like with mysqli_connect this is not...

mysqli bind variables

Hello, I have this partial code: if ($getRecords = $con->prepare("SELECT * FROM AUCTIONS WHERE ARTICLE_NO = ?")) { $getHtml = $con->prepare("SELECT ARTICLE_DESC FROM AUCTIONS WHERE ARTICLE_NO = ?"); $getHtml->bind_param("i", $pk); $getHtml->execute(); $getHtml->bind_result($ARTICLE_DESC); $getRecords->bind_param("i", $pk); $g...

How can I get every n rows in MySQL?

I have a table which contains data recorded every minute, so I have a row for each minute. When returning the data for processing, this accuracy is required for the last 6 hours but after that, a lower level of accuracy is sufficient, e.g. every 5 minutes. I can return all the data into an array and then remove all but every 5th element...

mysqli binding fields in a prepared statement

Hello, I have the following code, for which I get the error: Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement in file. If this is only a warning, shouldn't the code still work? I want to do a select * and display all the data except one field, w...

mysqli problem - prepared statements

Hello, I have the following snippet of code from my application, which should work. However, i get the error that: Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement in file. I am using the exact number of columns to bind as to select, and using l...

mysqli_stmt::bind_param and mysqli_stmt::prepare

Ok so i want to do a prepared insert such as: prepare("INSERT INTO `analyzeditemsdetails` SET analyzeditem_id = ? , start_time = ? , end_time = ? "); start_time and end_time are stored ...

prepared statement causing while loop error

Hello, I have the following simple mysqli php application, which should work fine. $pk is accepted perfectly and is a valid ARTICLE_NO, and the query works perfectly when executed directly by mysql. I have put output statements after every event and all except tetsing while executes. The while loop is never entered, and I am unsure why....

Javascript and MySQL

I want to build an entire web app using only Javascript and MYSQL . Anyone know how I can go about this if it's possible. Thank you. p ...

mysqli_use_result() and concurrency

According to the documentation at mysqli_use_result One should not use mysqli_use_result() if a lot of processing on the client side is performed, since this will tie up the server and prevent other threads from updating any tables from which the data is being fetched. Does this only pertain to myISAM tables or also for InnoDB? ...

PHP mysqli unexpected parameter Question

I feel like a total n00b for not understanding what I'm doing wrong, but here goes. I'm writing a simple web form that's storing information in a MySQL database. I'm getting this error: mysqli_stmt_init() expects parameter 1 to be mysqli, null given in /myfile.php Here's my code: $server = 'localhost'; $username = 'myusername'; $pas...

counting rows and passing information with mysqli

Hello, I have been trying to convert a php page to mysqli, and have encoutnered some problems. Given the code below, and the way which I have ordered things to work, I would like to know what the better way is using mysqli methods. Is there an mysqli alternative to mysql_num_rows or is a different method of calculating the number of ...

SQL LIKE query failing - fatal error in prepared statement

I have the following code: $countQuery = "SELECT ARTICLE_NO FROM ? WHERE upper(ARTICLE_NAME) LIKE '% ? %'"; if ($numRecords = $con->prepare($countQuery)) { $numRecords->bind_param("ss", $table, $brand); $numRecords->execute(); $data = $con->query($countQuery) or die(print_r($con->error)); $rowcount = mysql_num_rows($data...

Does mysqli class in PHP protect 100% against sql injections?

I've seen lots of articles and questions about mysqli, and all of them claim that it protects against sql injections. But is it fool proof, or is there still some way to get around it. I'm not interested in cross site scripting or phishing attacks, only sql injections. What I should have said to begin with is that I am using prepared st...

binding results into php array

I am trying the following code to get results from query and display it in the tes.php page. db.inc.php <?php function db_connect() { $handle=new mysqli('localhost','rekandoa','rekandoa','rekandoa'); if (!$handle) { return false; } return $handle; } function get_member() { $handle=db_connect(); $sql="Select email,na...

Commands out of sync; you can't run this command now1

I am trying to execute my php code, which calls two mysql queries via mysqli, and get the titular error. Here is the code I am using <?php $con = mysqli_connect("localhost", "user", "password", "db"); if (!$con) { echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error(); exit; } $con->query("SET NAMES 'utf8...

SQL like statement problems

I am having problems executing a prepared statement via mysqli. First I was getting Command out of sync errors. I am storing the result and closing the connection, and I have stopped getting this error, so hopefully the problem has stopped. However, the error in my sql syntax error, which was working fine while the commands were not in...

fetching data from a prepared statement.

I have a function, which is to return an array of rows containg records from a database, selected based on a LIKE query. I want this query to be a prepared statement for security reasons. Apparently I can not use bound parameters and the query function as I am doing. I am unsure then, of how to keep me query as a prepared statement, and ...

Insert variables and arrays in different database tables using PHP and MySQLi

Hi, I'm learning PHP and MySQL and I'm creating a movies website for learning purposes. I want to insert variables and arrays containing movie info into a database but in different tables. This is what I have right now: include('inc/connection.php'); $conn = dbConnect(); // create SQL $sql = 'INSERT INTO movies (movieid, title, year,...

Use "mysql_fetch_row" to retrieve results from database and insert into array using PHP and mysqli?

Hi, I need to retrieve data from several rows and then insert the results into an enumerated array so then I can use a "for" loop to echo it... I have this (I already connected to the database): $genres_sql = 'SELECT genreID FROM genres WHERE imdbID = ?'; if ($stmt->prepare($genres_sql)) { // bind the query parameters $stmt->bind_par...

Mixing PHP's mysqli data access functions?

I've seen a couple of questions over the last few days that have used mysqli but where the answers appear to have not recognised the difference between $stmt->execute() and $db->query(). As I understand it, there are two differing models for accessing results in mysqli. This one uses raw SQL and requires the programmer to escape the in...