mySQLi & PDO INSERT prepared statements don't work

Discussion in 'OpenLiteSpeed Bug Reports' started by DAVIDRUDMIN2, May 15, 2018.


    DAVIDRUDMIN2 New Member

    Although they both worked fine in Apache in which I coded them, yet here in OLS I have tried both PDO and mySQLi INSERT statements, . . . and neither one work.
    All I ever get is a PHP response that says, "[object Object]".
    Now I know that my database connection is good because my preceding SELECT statements do work.
    $stmt = $db->prepare("SELECT date FROM table1");
    $array = $stmt->fetchAll(PDO::FETCH_COLUMN);

    Here below are the two ways that I tried it, both of which failed:


    $db = new PDO('mysql:host=localhost; dbname=users; charset=utf8', 'root', 'xxx[password removed]xxxx');
    catch (PDOException $e) {
    echo $e->getMessage();

    $stmt = $db->prepare("INSERT INTO table1(name, date) VALUES ( :first_name, :time_stamp)");
    // The ": parameter" syntax is just a placeholder that gets filled in with the values below.
    $stmt->bindParam(':first_name' => $first_name);
    $stmt->bindParam(':time_stamp' => $time_stamp);


    $db = new mysqli('localhost', 'root', 'xxx[password removed]xxxx', 'users');
    if ($db->connect_error) {

    die("Connection failed: " . $db->connect_error);

    if (!$db) {
    die("Connection failed: " . mysqli_connect_error());

    $stmt = $db->prepare("INSERT INTO table1(name, date) VALUES (?, ?)");
    $stmt->bind_param("si", $first_name, $time_stamp);
    // s = string; i = integer

    I'm running OLS on the cheapest DigitalOcean Linux webserver droplet; however, this program was coded using Apache on a Windows 10 System. I'm also using php 5 (lsphp5), phpMyAdmin, and MariaDB. I also tried OLS's out-of-box php 7 (lsphp).
    Last edited: May 15, 2018
  2. Tishu

    Tishu Member


    So first check if everything is install for the php. You can create php file with "<?php phpinfo(); ?>" and open it or from the terminal "yum list installed | grep lsphp". After that check the mysql/mariadb version for your old and new server. They may be diff version with diff syntax.

    DAVIDRUDMIN2 New Member

    Okay, I just goofed. No, I did not find any flaw in OLS. (Sorry.)

    For starters, it looks like my PDO bindParam syntax (above) was wrong. Instead of . . .
    $stmt->bindParam(':first_name' => $first_name); should be...
    $stmt->bindParam(':first_name', $first_name);

    But in any case, I got this to work with the PDO option, above (in the original post):
    $sql = "INSERT INTO table1(name, date) VALUES ( :first_name, :time_stamp)";
    $stmt = $db->prepare($sql);
    $stmt->execute(array (

    ':first_name' => $first_name,
    ':time_stamp' => $time_stamp

Share This Page