mysqli

Using Mysqli bind_param with date and time columns?

How do you insert data into a MySQL date or time column using PHP mysqli and bind_param? ...

Mysqld [v5.0.51a] repeatedly restarting upon call to stored procedure

Hi, I'm repeatedly getting this in my server error log for MySQld. On my PHP (MySQLi) or SQL client (not sure what they use, maybe MySQLi as well) calling some (not all) stored procedures, this happens and I get the error message "Lost connection to MySQL server during query" (repeatedly). This procedure did actually work yesterday ;(. T...

MySql NOT NULL Constraint doesnot work

I am trying to implement NOT NULL constraint in the customer table which is created as: CREATE TABLE CUSTOMER( cust_id INT(5) NOT NULL AUTO_INCREMENT, PRIMARY KEY(cust_id), first_name VARCHAR(25) NOT NULL, last_name VARCHAR(25) NOT NULL, email VARCHAR(25) NOT NULL, password VARCHAR(25) NOT NULL, gende...

Is casting a mysqli result object to an array good practice?

Hey everyone, I was wondering, if I have some code such as: $result = $db->query($sql); // dont worry, its escaped $myData = (array)$result->fetch_assoc(); where $result->fetch_assoc(); returns a mysqli result object. Is casting it like this right away good practice? I would imagine this is an expensive call - is this true? It...

SQL query works on testing server but not live... what could be the difference?

SOLVED: I wrote and tested a PHP script on the local server. (Nothing fancy, just 2 consecutive SQL inserts in the same database, but different tables). Both servers run PHP5 & MYSQL 5. On the local server, both queries are processed correctly. On the live server, only the first query works, but not the second and I can't figure out ...

mysqli array -> query not attaining correct data

Hello, my mysqli_fetch_array(mysqi_query($db, $query)) doesn't appear to be getting the correct information from the database, and therefore, the PHP application is not working as it should. Here are the queries, <?php if($_GET){ $current = mysqli_fetch_array(mysqli_query($db, "SELECT * from `tbl_user` WHERE `userid` = '".$_GET['useri...

Batch inserts with PHP

Java has the PreparedStatement addBatch + executeBatch to do multiple insertions efficiently. What is the fasted way to do a batch of inserts using php's mysqli extension? Thanks! ...

Can PHP mysql and mysqli module connections to the same database be used side-by-side safely?

Say one were looking at transitioning a codebase from using the basic PHP mysql_* functions to a mysqli implementation. Can connections to the same database be used side-by-side in both interfaces, or is there some way in which they can interfere with one another? ...

Why do I get this function call error on an non-object when I am calling a function on an object?

Error: Fatal error: Call to a member function bind_param() on a non-object in /var/www/web55/web/pdftest/events.php on line 76 Code: public function countDaysWithoutEvents(){ $sql = "SELECT 7 - COUNT(*) AS NumDaysWithoutEvents FROM (SELECT d.date FROM cali_events e LEFT JOIN cali_dates d ON e.event_...

Is it worth using MYSQLI_CLIENT_COMPRESS when the db is on another machine?

I have two machines on amazon ec2, one with a drupal installation and another one with the mysql database. I wonder if it's worth to patch drupal to activate mysql client compression. Are there any caveats? ...

What does fetch in php do?

I don't understand the concept of the fetch function. I am doing a tutorial from 'PHP Solutions' book and i am using MySQL Improved to update something in the database. Here is the code: if (isset($_GET['article']) && !$_POST) { $sql = 'SELECT article_id, title, article FROM journal WHERE article_id = ?'; $stmt = $conn->stmt...

What mysqli function should I use?

Hello, I'm currently trying to extract data from a table, and am using this: $online = mysqli_fetch_field(mysqli_query($db, "SELECT `online` FROM `tbl_system` WHERE `property` = 'extranet'")); However, it's not working as echoing $online give "Array". Here's a var_dump from $online object(stdClass)#3 (11) { [...

How to echo a MySQLi prepared statement?

I'm playing around with MySQLi at the moment, trying to figure out how it all works. In my current projects I always like to echo out a query string while coding, just to make sure that everything is correct, and to quickly debug my code. But... how can I do this with a prepared MySQLi statement? Example: $id = 1; $baz = 'something'; ...

Mysqli Error: Column count doesn't match value count at row 1

Below is the mysqli query that is being performed, anyone know what I get such error: $sql = mysqli_query($db, "INSERT INTO `tbl_bugzilla` (`id`, `by`, `title`, `content`, `date`, `application`,`priority`, `assigned`, `status`) VALUES (NULL, '".$_SESSION['exp_user']['username']."', '" .$_SESSION['exp_user']['username']...

How to have multiple replies in posting app?

Hi, this is a simple question. With PHP and MySQL, I'm trying to build a bug reporting application. Currently, the user can post bugs and a list of bugs is portrayed to the technician/administrator. How do I make it so that many technician or administrators can reply to the report (thread?) As in both mysql table layout and PHP codi...

Stop continuous table generation

Hello, I am trying to stop the data in the following table from continuing to repeat itself, as in looping on the same data, crashing the browser: Here's the query: $posts = mysqli_fetch_assoc(mysqli_query($db, "SELECT * from tbl_bugresponse WHERE bugid = $id ORDER BY time")); And here's the table code: <table width="100%" class="tb...

How does a leftjoin work while using a initialized prepared statement for MySQLI?

The user comes to this page from a different page where they click on a link and it is appended with a ?photo_id= and then the id number. I want certain information to be available to the viewer when they arrive at this page. I want them to be able to see the photo, the photo name, and the photographers name. The first two are not a pro...

Good extension/wrapper for mysqli that returns a associated array for a prepared sql statement

Can anyone recommend a good wrapper class or extension to PHP's mysqli extension that allows the equivalent of mysql->fetch_assoc() for a prepared statement. That is ideally it condenses down into a single statement the tedious complexity of the init/prepare/bind/fetch-loop. ...

How do I update multiple tables using prepared statements with mySQLi?

I have a form with two fields with the name attribute of 'photo_title' and 'photographer_name', and a hidden field named 'photo_id'. When the user pushes the submit button, i want it to update two separate tables in the database. I can get it to update a single table, but as soon as I try to leftjoin the second table, it doesn't like it....

How can I put the results of a MySQLi prepared statement into an associative array?

I have a sql query and a mysqli prepared statement: $sql = 'SELECT photographers.photographer_id, photographers.photographer_name FROM photographers'; $stmt = $conn->stmt_init(); if ($stmt->prepare($sql)) { $stmt->bind_result($photographer_id, $photographer_name); $OK = $stmt->execute(); $stmt->fetch(); } How can...