mysqli

mysqli and php fetch object

Hi, I have the following code: $sql_latest = "SELECT * FROM tbl_latest ORDER BY id DESC LIMIT 0,3 "; $results_latest = $mysqli->query($sql_latest); while($row = $results_latest->fetch_object()) { echo $row->id; } How can I get the results into a array so I can do something like echo $row[1]; echo $row[2]; echo $row[2]; ...

convert mysqli result to json

Hey everyone, I have a mysqli query which i need to format as json for a mobile application. I have managed to produce an xml document for the query results, however i am looking for something more lightweight. (see below for my current xml code) Any help or info greatly appreciated people! $mysql = new mysqli(DB_SERVER,DB_USER,DB_PA...

what mysqli functions to use instead of mysql?

This will probably sound pretty dumb. I've got a mysql function containing the following... @mysql_connect() @mysql_select_db($databaseName,$link); mysql_query($sql,$link); mysql_error() mysql_fetch_array($result,MYSQL_ASSOC) mysql_num_rows($result) Can I just bung an i after mysql like this... @mysqli_connect mysqli_query($l...

real_escape_string vs. prepared statements

is there any reason to use one over the other in terms of speed and safety? Thanks! ...

PHP mysqli->real_escape_string when using sessions saved in the DB

Ok, I hope I've got everything listed up nicely before posting this question because I've found bits and pieces of a solution here and there but no real answer to my issue. 1: I'm using a singleton MySQL connection with mysqli, not using stored procedures; 2: I found code online explaining session_set_save_handler and have embedded it ...

php and mysql, best practices

I started working with php and mysql today. Basically, what I have, is an empty page with pieces that I fill in from looking up an id in a database. So on my home page I have an url that looks like this: <a href="content/display.php?id=id1"> And then in my display.php I have this: <?php include '../includes/header.php'; $i...

mysqli prepared statement with operator

Hi, I am trying to do the following: $search_query = "SELECT spec, title, quantity, location_to, location_from FROM sm12761.assignments WHERE title = ? LIMIT 0,1 "; But change it to WHERE title LIKE '&something%' How would I do this ? If some one could show me a refactored version of the query that woul...

Getting error: Cannot use object of type mysqli_result as array

I'm following a php pagination tutorial that uses MYSQL but I use MYSQLI object oriented all around my site. This is causing some errors.. For this part.. $sql = "SELECT COUNT(*) as num FROM categories"; $total_pages = $connection->query($sql) or die(mysqli_error($connection)); $total_pages = $total_pages['num']; I get *Fatal error:...

mysqli prepare statement using select failing for some unknown reason

Why is this failing? I am connected to the correct db, and keys is definitely there. //verify key against key list in database if ($prep_statement = $db->prepare("SELECT id FROM key_list WHERE keys=?")) { $prep_statement->bind_param('s',$key); $prep_statement->execute(); echo $prep_statement->num_rows; $prep_statement->...

mysqli statement: fetch() an array of results

I use mysqli extension and bind the result to an object: class Item { public $id, $name; } $Item = new Item; $stmt->bind_result($Item->id, $Item->name); Every call to $stmt->fetch() will overwrite $Item's properties which became references. If I simply clone the object — these references remain and both instances change simult...

mysqli connect problem

This is weird. I have 2 centos boxes, prod (192.168.0.1) and vm (192.168.0.30). Mysql database sits on prod. App sits on vm. From vm, if I type mysql -u user -p -h 192.168.0.1 -D mydb it connects lovely, so port is open and listening on prod but in app, i do $db=new mysqli('192.168.0.1','user','mypass','mydb'); and I get Warnin...

PHP MySQLi prepared statements store_result()

Can anyone tell me why my scripts will run out of memory (allocating over 16MB) for a prepared statement that shouldnt need even close to that? The only way I can fix it is by running store_result() before i run bind_result() I am assuming that by using store_result() it tells the script exactly how much memory the statement needs and i...

using mysqli to fetch data

i've been trying my hand at mysqli. using procedural mysql, the code displays the results fine. however, after making the switch to OOP mysqli, i tried converting the code to mysqli, and it says there are no quotes. is there anything wrong with the code? /* the database object */ private $_db; public function __constr...

mysqli resultset displays null

i'm trying to use mysqli to display data, but it displays nothing. what is wrong with my code? php class: /* the database object */ private $_db; public function __construct($db=NULL) { if(is_object($db)) { $this->_db = $db; } else { ...

Fatal error: Class 'MySQLi' not found

Fatal error: Class 'MySQLi' not found in D:\Hosting\6448289\html\database.php on line 8 database.phph file - <?php $db_name = "szdb"; $db_server = "localhost"; $db_user = "root"; $db_pass = ""; $mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error()); ?> why I am getting this fetal error? ...

stmt->bind_params dynamically? PHP

How would it be best to approach this task? require_once('models/databaseModel.class.php'); class crudModel extends databaseModel{ public function __construct(){ parent::__construct(); } public static function create(&$data, $tbl){ // TEST $data array // $data = array('name'=>'philip','email'=>'[email protected]','age'=>2...

How to show MYSQL statements that show how to create a particular table?

Hi, I've created and edited a couple of tables and don't want to recreate them from scratch if the database gets erased. What command allows me to "export" the field names and settings (NOT the content) as a ready to use MYSQL command that I can paste back on the MYSQL prompt? ...

mysqli persistant connection

In short, is there some sort of mysqli_pconnect for high-usage PHP & MySQL servers, or do I need to stick with mysql unimproved? And if so, why did they remove it? ...

mysqli object how do I get the fields

Hi. I tried this: $result = $conn->query("SELECT * FROM temp_users WHERE reg_code ='$passkey'"); This works: if($result->num_rows == 1){ values from print_r($result); mysqli_result Object ( [current_field] => 0 [field_count] => 11 [lengths] => [num_rows] => 1 [type] => 0 ) but $result->username where username is a field in the d...

Num Rows always ='s 1 for some reason. QUICK FIX

I don't know if i am doing it right, this is what I got: while($row = mysqli_fetch_assoc($result)) { $items = mysqli_num_rows($row); } It always sets $items = to 1 for some reason. Here is my mysqli_query... $top10_query = "SELECT * FROM users WHERE userid='$userid'"; $result = mysqli_query($cxn, $top10...