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...
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 :)
...
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...
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...
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).
...
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...
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...
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.
...
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...
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 ...
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 ...
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 = $...
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?
...
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 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?
...
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...
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...)
...
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...
Are MySQLi queries unbuffered? If not, is there a way to do an unbuffered query, as with the non-MySQLi mysql_unbuffered_query()?
...
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...