mysqli

Can a MYSQLI connection be reopened WITHOUT instantiating a new object.

Hi All, Just a quick question here: If I choose the object oriented style to interact with my database, ie... $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); And I then use $mysqli->close(); to close the connection at some point... Can I reopen that connection by simply initiating another query $mysqli->quer...

mysql optimization with IN or OR

Dear all, I have a set of large values that need to be compared in mysql. May I know which is faster? For example: Opt 1: SELECT * FROM table WHERE v = 1 or v = 2 or v = 3 or v = 4 or... v = 100 Opt 2: SELECT * FROM table WHERE v IN (1,2,3,4,5,6,7,8,...,100) May I know which option is faster for large value? Is there any better s...

Can't Connect to MySQL Server on IPAddress (10061)

Hi, I need to connect to a remote MySQL database and have created the following connection code: <?php /* Set Variables */ $host="myipaddress"; $db="mydbname"; $username="dbuser"; $pass="mypass"; /* Attempt to connect */ $mysqli=new mysqli($host,$username,$pass,$db); if (mysqli_connect_error()){ die('Connect Error (' . mysqli_connect...

multi_query in php

I have a database 'test' with two tables. Here is phpmyadmin dump: CREATE TABLE IF NOT EXISTS `tags` ( `name` varchar(100) NOT NULL, `id` int(4) NOT NULL, KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `tags` -- INSERT INTO `tags` (`name`, `id`) VALUES ('tag_one', 1), ('tag_two', 1), ('tag_th...

mysqli_commit not working?

The function below, as its name suggests, registers/records the data from signup form into the database. In order to avoid table addresses from getting the wrong adressID(which references members(memberID)), I have to wrap the two insert queries into members and addresses respectively with autocommit and commit. function register($un, $...

Bind_param Non-Object Error w/ mysqli

When attempting to insert the initial row for a table that will track daily views, I am getting the error: Fatal error: Call to a member function bind_param() on a non-object in /.../functions.php on line 157 That line is the last of the following group: if($stats_found) { $sqlquery = "UPDATE vid_stats SET views = ? WHERE title =...

How do I redirect to another page after mysqli runs succesffully?

Hi, I have written the following in my reginsert.php. The goal is to take the variables from index.php and insert into my regdata table. After successful insert is completed, I want the user redirected to thank_you.html. Where/how would I incorporate that in the following code block? <?php $Database = array( "Host" => 'myhost', "Use...

How to login a user authenticating username and password against a MySQL database?

Hi All Nightowls out there :), I need to authenticate username and password provided on a login page against my database table, named regdata. Upon successful authentication, the user is taken to /countdown_clock/countdown.html. When I run the page, I'm not taken to the specified countdown.html, but the same page refreshes with /auth...

prepare() vs query() mysqli

I am trying to understand the difference between mysqli's query() and prepare(). I have code like below, and I would like to get the same results from both. However the prepare() does not work as expected. why? // this works if ($query = $this->db->query("SELECT html FROM static_pages WHERE page = 'cities'")) { $result = ...

Simple error checking with mysqli?

I'm using $mysqli->query all over the place without any sort of error checking or fall back if the query fails. What's the simplest/cleanest method I can use to catch these ? I'm thinking of a little function which can just display a friendly message and send me an email - I can write that but am not sure how to trigger/call it only w...

Why do i have to use set_charset("utf8") even though everything is utf-8 encoded? (MySQLi-PHP)

My table's collation is utf8_general_ci. My pages are encoded with UTF-8 (without BOM). Within my pages, my Equiv meta tag sets character set to utf8 My data has Turkish characters in it. When i output them, it's not showing them as it should be but when i do $db->set_charset("utf8");, it works. Why do i have to use $db->set_charset...

php DBAL for MySQLi/MSSQL row fetching

I'm trying to write a simple, thin and efficient database abstraction layer on top of the PHP MySQLi (procedural) and MSSQL libraries, to be used like this... while ($a = db::go('db_name')->query('select * from foo')->row()) { print_r($a); } I have the class written, but am struggling somewhat with how best to loop through the resul...

My project works fine on my local machine, but not on the web server

My project is working fine on my local machine but not on the web server. I think it is the stored procedures, because the error that I am getting is: Fatal error: Call to a member function fetch_array() on a non-object in ... The collation of the database is "utf8_general_ci". Just a simple example: I have a stored procedure cal...

PHP, MySQL and a large nummer of simple queries

Hi stackies, I'm implementing an application that will have a lot of clients querying lots of small data packages from my webserver. Now I'm unsure whether to use persistent data connections to the database or not. The database is currently on the same system as the webserver and could connect via the socket, but this may change in the ...

Proper usage of MySQLi

Can anyone instruct me on the proper way to use the MySQLi extension in PHP? I have always used procedural MySQL functions before and want to make the change but am finding the examples on PHP.net and other sites way too complicated. There seems to be multiple methods to do the same thing. I want to use it in the following method: funct...

num_rows method not bringing back number of selected rows

This is the code: $q = $this->db->prepare("SELECT id FROM `users` WHERE username=? AND password=? LIMIT 1"); $q->bind_param('ss', $username, $password); $q->execute(); printf('Rows returned: %i', $q->num_rows); I am using MySQLi to try and check a users login credentials. Everything works and the query gets executed and data is retur...

MySQLi count(*) always returns 1

I'm trying to count the number of rows in a table and thought that this was the correct way to do that: $result = $db->query("SELECT COUNT(*) FROM `table`;"); $count = $result->num_rows; But counts always returns (int)1. If I use the same query in phpMyAdmin I get the right result. It sits in a table so I tried testing $count[0] as we...

Do the benefits of mysqli warrant rewriting a large, working system?

I apologize if this question is a duplicate. I have read many other mysqli questions first, but none seemed to be an exact duplicate. I am the senior developer on a project my company has been working on for 4+ years. It's a large PHP MVC framework system with modules for a CMS system, an eCommerce system, and more. In total we're talki...

mysqli giving "Commands out of sync" error - why?

I am trying to run the following. <?php $db = mysqli_connect("localhost","user","pw") or die("Database error"); mysqli_select_db($db, "database"); $agtid = $_POST['level']; $sql = sprintf("call agent_hier(%d)", $agtid); $result = mysqli_query($db, $sql) or exit(mysqli_error($db)); if ($result) { echo "<table border='1'> ...

MySQLi Prepared Statements?

Hi, I have decided to take the plunge into the improved MySQL by using MySQLI . Problem is i cannot find any in depth yet simply put tutorials online. The ones i have found are very short and or does not really explain anything. I know you have the php website but to tell you the truth it is really not a easy tutorial to follow, it's a...