mysqli

PHP Prepared Statement Returns -1

I've been using prepared statements for a little while now and I've never had any problems. Now I'm trying to: $sql="SELECT PhotoID,Caption FROM Photos WHERE EntityID=? AND TypeID=? LIMIT ?,?"; $iDB = new mysqliDB(); // Extends mysqli $stmt = $iDB->prepare($sql); $stmt->bind_param('iiii',$entityID,$typeID,$minRange,$maxRange); $stm...

Query design in SQL - ORDER BY SUM() of field in rows which meet a certain condition

OK, so I have two tables I'm working with - project and service, simplified thus: project ------- id PK name str service ------- project_id FK for project time_start int (timestamp) time_stop int (timestamp) One-to-Many relationship. Now, I want to return (preferably with one query) a list of an arbitrary number of projects, sorted ...

MySQLi prepared statements error reporting

I'm trying to get my head around MySQli and I'm confused by the error reporting. I am using the return value of the MySQLi 'prepare' statement to detect errors when executing SQL, like this: $stmt_test = $mysqliDatabaseConnection->stmt_init(); if($stmt_test->prepare("INSERT INTO testtable VALUES (23,44,56)")) { $stmt_test->execute(); ...

mysql select from a table depending on in which table the data is in

I have 3 tables holding products for a restaurant. Products that reside in the bar, food and ingredients. I use php and mysql. I have another table that holds information about the orders that have been made so far. There are 2 fields, the most important ones, that hold information about the id of the product and the type (from the bar,...

PHP mysqli wrapper: passing by reference with __call() and call_user_func_array()

Hi everyone. I'm a long running fan of stackoverflow, first time poster. I'd love to see if someone can help me with this. Let me dig in with a little code, then I'll explain my problem. I have the following wrapper classes: class mysqli_wrapper { private static $mysqli_obj; function __construct() // Recycles the mysqli object ...

Searching with MATCH(), AGAINST() and AS score with mysqli and php

Below is the code I am using to search my table. I have made the relevant columns FULLTEXT in the table. This doesn't return me anything. Can someone tell me what it is that i'm doing wrong? Thanks in advance. $sql = 'SELECT id, person_name, classroom, school, MATCH (person_name, classroom, school) AGAINST (?) AS score FROM images WHERE...

PHP MySQLi and MySQLi_STMT: Which insert_id to use?

Hello all, Both the MySQLi and MySQLi_STMT classes have an $insert_id property. If I am connected to my database using a MySQLi object (say $db), and then I perform an INSERT with a MySQLi_STMT object (say $stmt), to get the id of the last INSERT, should I use: $last_id = $db->insert_id; or $last_id = $stmt->insert_id; Or would ...

fetch_all or fetch_assoc MySQLi statement

Hi, is it possible to use the fetch_all(), fetch_assoc() etc. from the the MySQLi_Result class with a prepared statement from the MySQLi_STMT class? I've done it using the query() method in the Mysqli class (and by escaping trough mysqli_real_escape_string()), but not using statements with binding parameters. I'm considering using PDO ...

Help PHP Login not working correctly?

Ok so I am trying create a login script, here I am using PHP5 and mysqli, I would to ask if you could let me know why it keeps just returning "the error: your username and password does not match any in our db"? when I have created the an account and it clearly does? It's probably something obvious I've missed. Heres the code... //Check...

PHP MYSQLI query error?

Hey This is my login script, using PHP5 and MYSQLi, I just had help spotting errors in my query, but still it will not let me login, even though the username and password are correct and in the database, it just keeps returning the error: your username and password do not match any in our db. But I know they do lol...could any body spot ...

checkUnique function?

Hey, so I have created a function to check the DB for unique entries, but when I call the function it doesn't seem to work and gives me a fatal error any ideas from the function or do you wish to see the sign up page calling it. Thanks :) //Check for unique entries function checkUnique($table, $field, $compared) { ...

Fatal error on a non-object

Hey, so I have created a function to check the DB for unique entries, but when I call the function it doesn't seem to work and gives me a fatal error any ideas ? Thanks :) //Check for unique entries function checkUnique($table, $field, $compared) { $query = $mysqli->query('SELECT '.$mysqli->real_escape_string($f...

How Do I See The Final Text Of A Query Resulting From A Call To mysqli->prepare?

After code like this: $stmt = $mysqli->prepare("SELECT District FROM City WHERE Name=?")) { $stmt->bind_param("s", $city); $stmt->execute(); $stmt->bind_result($district); $stmt->fetch(); printf("%s is in district %s\n", $city, $district); How Do I See The Actual SQL Statement That Was Executed? (It Should Look Something Like "SELECT...

Strange PHP array behavior overwriting values with all the same values

Im doing a simple mysqli query with code ive used many times before but have never had this problem happen to me. I am grabbing an entire table with an unknown number of columns (it changes often so i dont know the exact value, nor the column names). I have some code that uses metadata to grab everything and stick it in an array. This a...

PHP mysqli Insert not working, but not giving any errors.

As the title says Im trying to do a simple insert, but nothing actually is inserted into the table. I try to print out errors, but nothing is reported. My users table has many more fields than these 4, but they should all default. $query = 'INSERT INTO users (username, password, level, name) VALUES (?, ?, ?, ?)'; if($stmt = $db -> prep...

MySQL charset conversion

Hello, I have a database in which all text fields and tables have 'utf8' specified explicitly as default character set, however data in this database is stored as 'cp1257'. I can display symbols only when I use SET NAMES 'cp1257' or \C cp1257. Trying to display them without those instructions fails, because it tries to fetch data as 'utf...

Is there any way to print the actual query that mysqli->execute() makes?

I have a complex query that gets executed like this: if ($stmt = $dbi->prepare($pt_query)) { $stmt->bind_param('ssssssssi', $snome,$scognome,$ssocieta,$svia,$slocalita,$sprovincia,$scap,$stelefono,$sfax,$uid); $stmt->execute(); echo $dbi->error; $stmt->close(); } else { printf("...

How can I specify that Doctrine must use a mysqli-connection

Hi, while executing a long script that uses Doctrine to access the db, I get an error 2006 server has gone away. I've already solved this problem on a website that doens't use Doctrine. The solution there was to use mysqli instead of the normal mysql driver. How can i tell Doctrine to use a mysqli-driver in order to avoid 2006-errors? ...

PHP PDO - Num Rows

PDO apparently has no means to count the number of rows returned from a select query (mysqli has the num_rows variable). Is there a way to do this, short of using count($results->fetchAll()) ? ...

Php mysqli and stored-procedure

I have a stored procedure: Create procedure news(in dt datetime,in title varchar(10),in desc varchar(200)) Begin Insert into news values (dt,title,desc); End Now my php: $db = new mysqli("","","",""); $dt = $_POST['date']; $ttl = $_POST['title']; $desc = $_POST['descrip']; $sql = $db->query("CALL news('$dt','$ttl','$desc')"); if($s...