mysqli

Extending the MySQLi class

I want to be able to make classes which extend the MySQLi class to perform all its SQL queries. $mysql = new mysqli('localhost', 'root', 'password', 'database') or die('error connecting to the database'); I dont know how to do this without globalising the $mysql object to use in my other methods or classes. class Blog { public funct...

mysqli query, LIKE and AND in the same query doesn't work out like it should

so this is my query, it doesn't matter if approved is set to 0 or 1 it will give me all the rows anyway SELECT * FROM `tutorials` WHERE tags LIKE '% php %' OR tags LIKE 'php %' OR tags LIKE '% php' OR tags = 'php' AND approved=1 I guess it's because of the OR but I might be wrong, if someone could help me out on this :) ...

Mysqli abstraction, fetching arrays from prepared statements

Lately I've stumbled upon an error in a lib that used to work just fine, and I'll be damned if I can figure out where it is. The code sample is below, and I apologize for the debug stuff that's inside it, but I'm trying to get it to work. The problem is that $temp is an array with correct key (the name of the columns) but all the value...

mysql - update two records at once

Using PHP's msqli is it possible to update two records with one query? First I do a SELECT to check that $pay_user has enough game currency in his account, if he does then I do the following... My update query is: "UPDATE account SET money= money - ".$money." WHERE User_id=".$pay_user "UPDATE account SET money= money + ".$money." WH...

mysqli_field_type returns a number

When I call mysqli_field_type it returns a number, which I assume relates to the type. Does anyone have a list of types and their corresponding numbers? I am in particular trying to find out if the data type is numerical or text (if that makes a difference). ...

PHP, MySQL - would results-array shuffle be quicker than "select... order by rand()"?

I've been reading a lot about the disadvantages of using "order by rand" so I don't need update on that. I was thinking, since I only need a limited amount of rows retrieved from the db to be randomized, maybe I should do: $r = $db->query("select * from table limit 500"); for($i;$i<500;$i++) $arr[$i]=mysqli_fetch_assoc($r); shuffle($arr...

Create stored procedure in mysqladmin?

I am trying to create stored procedure in mysql admin. I am hosting a website in POWWEB.com. For this purpose i am trying to create stored procedure in mysqladmin. The Mysql version is 5.0.45. I am able to create a stored procedure with only 1 line of code. CREATE PROCEDURE TEST(input INT) INSERT INTO TEST(COL1) VALUES(input...

PHP: Dealing With MySQL Connection Variable

What is the best way to deal with the $db_conn variable once I create a mysqli object? I've been using $GLOBALS['_sql'] = new mysqli(...); But this seems dirty. The alternative that I've seen is to be constantly passing the connection var to every function that calls it, but that's a huge pain. ...

MySQLI binding params using call_user_func_array

Hello, Please see below my code. I am attempting to bind an array of paramenters to my prepared statement. I've been looking around on the web and can see I have to use call_user_func_array but cannot get it to work. The error I get is: "First argument is expected to be a valid callback, 'Array' was given" I may be wrong but I'm assumin...

Getting row data of inserted row (Mysql, PHP, mysqli)

I need to get back the postid (auto-incrementing PK) of a row when i insert it. I am currently using this to get it //get postid to return if($result = $db -> query('SELECT postid FROM posts WHERE title = \''.$title.'\' LIMIT 1')){ $row = $result->fetch_assoc(); $json['postid'] = $row['postid']; $result->free(); where $title ...

PHP how to check if a MySQLi query needs to be closed?

I created a simple MySQLi class for a project I'm working on to make it easier and more streamlined to pull from and push to the DB. (also to get more familiar with OOP in PHP) A problem I keep running into is in an effort to make it as efficient as possible. I try to close / free every query / statement / result set. In doing so I get ...

What's the problem with mysqli in php5?

I used to code in php4 but now I switched to php5 and the following code throws the below exception. Why is that? CODE: $mysqli = new mysqli($CONFIG_DB_HOST,$CONFIG_DB_USERNAME,$CONFIG_DB_PASSWORD,$CONFIG_DB_NAME); $result = $mysqli->query("select * from temp_table where url = '" . $mysqli->real_escape_string($in_url) . "'"); $row = $...

For a review website, which language?

I am thinking of building a review website and i was thinking about using php. What language would be good for a website like ratemyprofessor? would ruby be better? ...

How to print the actual SQL query to a file?

Say, this is my query $stmt = "SELECT * FROM foo WHERE x=?"; How do I print the above query plus the bound parameter to the screen or to a file in PHP? When I print $stmt it says: mysqli_stmt could not be converted to string Here's my code: if ($stmt = $this->conn->prepare($query)) { $stmt ->bind_param('ss', $un, $pwd); ...

Why should I free the result of PHP and MySQL?

Why should I free the result of PHP and MySQL using mysql_free_result()? And what is the difference whether I free the result or not? Should I always free the result from a MySQL query result specially in CRUD? Thanks for answering my questions? ...

A non-prepared query using MySQLi and Zend_DB

Due to a bug in my servers PDO version, I have switched to using MySQLi. However, this presents another problem, as the Zend_DB MySQLi adaptor doesn't have an exec function. (The Zend PDO adaptor did), which means I can't execute a sql script. (Containing a load of DROP TABLE and CREATE TABLE queries). So where I could just do: $sqlQue...

MySQL vs MySQLi in PHP

What are the differences/advantages of each? Disadvantages? I'm not looking for coding preferences or subjective answers. What are practical diferences? (Storage, implementation, how the code looks, environment requirements...) ...

Is it possible to use mysqli_fetch_object with a prepared statement

All the examples I see using mysqli_fetch_object use mysql_query(), I cannot get it to work with prepared statements. Does anyone know what is wrong with this code snippet, as fetch_object returns null. $sql = "select 1 from dual"; printf("preparing %s\n", $sql); $stmt = $link->prepare($sql); printf("prepare statement %s\n", is_null($st...

unbuffered query with MySQLi?

Are MySQLi queries unbuffered? If not, is there a way to do an unbuffered query, as with the non-MySQLi mysql_unbuffered_query()? ...

phpmyadmin using mysqli connects, but my php using mysqli errors out

This is driving me nuts! I am getting the classic "Can't connect to local MySQL server through socket '/var/run/mysql4d/mysql4d.sock' (13)". Everything I've dug up so far tells me my setup should be OK (eg, defining the sockets in php.ini and my.cnf, etc). Worse... phpmyadmin works with the same un/pw I am using in my own php. So o...