/    Sign up×
Community /Pin to ProfileBookmark

Why Mysqli Prepare Failed ?

Php Experts,

I can’t remember what I changed last night that is making the following code malfunctioning. Can you see if you can spot any typos ?

[code]
$sql_query = “UPDATE users SET first_name = ?, middle_name = ?, surname = ?, gender = ?, marital_status = ?, working_status = ?, agree_to_tos = ? WHERE id = ?”;

$stmt = mysqli_prepare($conn,$sql_query);

if($stmt == False)
{
//Close Connection.
mysqli_close($conn);
die(“<pre>2. Mysqli Prepare Failed!n”.mysqli_stmt_error($stmt).”n$sql_query</pre>”);
}
[/code]

I get this error echoed:
**Warning: mysqli_stmt_error() expects parameter 1 to be mysqli_stmt, boolean given in C:xampphtdocspower.pagesearch_3.php on line 416

  • 2. Mysqli Prepare Failed!
  • UPDATE users SET first_name = ?, middle_name = ?, surname = ?, gender = ?, marital_status = ?, working_status = ?, agree_to_tos = ? WHERE id = ?**

    How to solve this ?

    to post a comment

    9 Comments(s)

    Copy linkTweet thisAlerts:
    @developer_webauthorMay 31.2020 — "I found the cause of my ignorance" - Bruce Lee

    https://www.google.com/search?client=firefox-b-d&q=i+found+the+cause+of+my+ignorance+-+Bruce+lee


    https://www.youtube.com/watch?v=ll11FP35ThQ

    NogDog,

    I found the cause of my ignorance.

    On the script, I added a new column last night but did not add it on mysql table.

    "agree_to_tos".

    Added it now and error gone.

    "Hence, I found the cause of my ignorance".

    But I did not find the "cause of the ignorance" of both php and mysql.

    Why didn't php atleast give me an error stating the "agree_to_tos" column doesn't exist ? How to fix this so I don't go round & round in circles again when I add a new placeholder in the script but forget to add a new column representing it ?
    Copy linkTweet thisAlerts:
    @developer_webauthorMay 31.2020 — New problem!

    Folks,

    Can you spot any typos here:
    <i>
    </i>$sql_query = "SELECT first_name,middle_name,surname,gender,marital_status,working_status FROM users WHERE id = ?";
    $stmt = mysqli_prepare($conn,$sql_query);
    mysqli_stmt_bind_param($stmt,'i',$_SESSION["user_id"]);;//DELETE THIS WHOLE LINE AS USING IT AS A TEST!

    if($stmt == False)
    {
    //Close Connection.
    mysqli_close($conn);
    echo "Line 862&lt;br&gt;";//DELETE THIS
    die("&lt;pre&gt;2. Mysqli Prepare Failed!n".mysqli_stmt_error($stmt)."n$sql_query&lt;/pre&gt;");
    }
    else
    {
    //Attempt to Execute the Prepared Statement.
    mysqli_stmt_execute($stmt);
    if(!mysqli_stmt_execute($stmt))
    {
    //Close Connection.
    mysqli_close($conn);
    echo "Line 915&lt;br&gt;";//DELETE THIS
    die("&lt;pre&gt;Statement Execution Failed!n".mysqli_stmt_error($stmt)."n$mysqli_stmt_bind_param&lt;/pre&gt;");
    }
    else
    {
    die("&lt;pre&gt;Statement Execution Success!&lt;/pre&gt;");
    }
    }
    //mysqli_stmt_bind_result($stmt,$email);
    $result = mysqli_stmt_get_result($stmt);
    //if(mysqli_fetch_array($result_3, MYSQLI_NUM))
    //Fetch result row as an associative array. Since the result set contains only one row, we don't need to use the 'While loop'.
    //mysqli_stmt_fetch($stmt);//use this if you use 'mysqli_stmt_bind_result($stmt,$email).
    if($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) //Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of 'mysqli_stmt_bind_result($stmt,$email)'.
    {
    //Retrieve Values.
    //$id = $row["id"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $username = $row["username"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $first_name = $row["first_name"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $middle_name = $row["middle_name"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $surname = $row["surname"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $gender = $row["gender"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    //$age_range = $row["age_range"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $marital_status = $row["marital_status"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $working_status = $row["working_status"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    //$country = $row["country"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';

    <i> </i>//echo "Id: $id&lt;br&gt;";
    <i> </i>//echo "Username: $username&lt;br&gt;";
    <i> </i>echo "First Name: $first_name&lt;br&gt;";
    <i> </i>echo "Middle Name: $middle_name&lt;br&gt;";
    <i> </i>echo "Surname: $surname&lt;br&gt;";
    <i> </i>echo "Gender: $gender&lt;br&gt;";
    <i> </i>//echo "Age Range: $age_range&lt;br&gt;";
    <i> </i>echo "Marital Status: $marital_status&lt;br&gt;";
    <i> </i>echo "Working Status: $working_status&lt;br&gt;";
    <i> </i>//echo "Country: $country&lt;br&gt;";
    <i> </i>
    <i> </i>//Close Statement.
    <i> </i>mysqli_stmt_close($stmt);
    <i> </i>//Free Result.
    <i> </i>mysqli_free_result($result);//Is this line necessary if using mysqli_stmt_get_result() ?
    <i> </i>//Close Connection.
    <i> </i>mysqli_close($conn);
    }



    I get echoed

    **Statement Execution Success!**

    But I see nothing echoed from mysql tbl. No data atall!

    I need to know if this line is necessary or not if I use mysqli_stmt_get_result() instead of mysqli_stmt_bind_result(). I reckjon I do not need it.
    <i>
    </i>mysqli_free_result($result);//Is this line necessary if using mysqli_stmt_get_result() ?



    Copy linkTweet thisAlerts:
    @NogDogMay 31.2020 — > @developer_web#1618992 $result = mysqli_stmt_get_result($stmt);

    Get rid of that line, too. It's incrementing the result row pointer, so that when you do the fetch a few lines later it thinks there are no more result rows.
    Copy linkTweet thisAlerts:
    @developer_webauthorJun 02.2020 — @NogDog#1618993

    NogDog,

    Getting rid of these 2 lines as you suggested throws following error:
    <i>
    </i>$result = mysqli_stmt_get_result($stmt);
    mysqli_free_result($result);


    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:xampphtdocspower.pagesearch_3.php on line 934

    I spotted on tutorials now that, if you use mysqli_stmt_get_result($stmt), then you have to use mysqli_stmt_init().

    https://www.phptutorial.info/?mysqli-stmt.get-result

    I used that now and it is working.

    But the funny thing is NogDog, I did not use the mysqli_stmt_init() on another file and that one still worked to echo the rows. How so ? Try answering me on that.

    I did it like this on that other one and it is echoing the rows.

    Look, no mysqli_stmt_init() with mysqli_stmt_get_result($stmt) plus mysqli_stmt_free_result($stmt) exists.

    Look at that other working one ....
    <i>
    </i>&lt;?php

    session_start();

    if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
    if(!isset($_POST['email_account']) || !isset($_POST['email_service']))
    {
    $email_error = "&lt;font color='red'&gt;Input Email Address!&lt;/color&gt;";
    }
    else
    {
    //Connect to Database. (DB_SERVER, BD_USERNAME, DB_PASSWORD, DB_NAME).
    $conn = mysqli_connect("localhost","root","","powerpage");
    $conn-&gt;set_charset('utf8mb4'); //Always set Charset.

    <i> </i> if($conn === false)
    <i> </i> {
    <i> </i> die("ERROR: Connection Error!. " . mysqli_connect_error());
    <i> </i> }
    <i> </i> else
    <i> </i> {
    <i> </i> //Set Parameters.
    <i> </i> $email = trim($_POST["email_account"]) . '@' . trim($_POST["email_service"]);
    <i> </i> $_SESSION['email'] = trim($_POST["email_account"]) . '@' . trim($_POST["email_service"]);//If this fails on test then replace it with above line
    <i> </i> echo "line 25 triggered: $email&lt;br&gt;";
    <i> </i>
    <i> </i> $sql_query = "SELECT COUNT(personal_email) FROM users WHERE personal_email = ?";
    <i> </i> $stmt = mysqli_prepare($conn,$sql_query);
    <i> </i> if($stmt == False)
    <i> </i> {
    <i> </i> //Close Connection.
    <i> </i> mysqli_close($conn);
    <i> </i> echo "Line 33&lt;br&gt;";//DELETE THIS
    <i> </i> die("&lt;pre&gt;Mysqli Prepare Failed!n".mysqli_stmt_error($stmt)."n$sql_query&lt;/pre&gt;");
    <i> </i> }
    <i> </i> else
    <i> </i> {
    <i> </i> mysqli_stmt_bind_param($stmt,'s',$email);
    <i> </i>
    <i> </i> if(!mysqli_stmt_execute($stmt))
    <i> </i> {
    <i> </i> //Close Connection.
    <i> </i> mysqli_close($conn);
    <i> </i> die("Could not mysqli_stmt_execute! Please try again later!");
    <i> </i> }
    <i> </i>
    <i> </i> //$result = mysqli_stmt_bind_result($stmt,$email);
    <i> </i> //$result = mysqli_stmt_store_result($stmt);
    <i> </i> $result = mysqli_stmt_get_result($stmt);
    <i> </i>
    <i> </i> if(mysqli_fetch_array($result, MYSQLI_NUM)[0])
    <i> </i> //($result-&gt;fetch_array()[0]) //DELETE THIS. THIS ALSO NOT RETYPED.
    <i> </i> //if(mysqli_fetch_array($result, MYSQLI_NUM)) //WHY THIS NOT WORK UNLESS NUM ARRAY GIVEN ?
    <i> </i> {
    <i> </i> echo "Line 57 triggered: Function login() will trigger!&lt;br&gt;"; //DELETE THIS
    <i> </i> $_SESSION['session_type'] = 'login';
    <i> </i> login();
    <i> </i>
    <i> </i> }
    <i> </i> else
    <i> </i> {
    <i> </i> echo "Line 61 triggered: Function register() will trigger!&lt;br&gt;"; //DELETE THIS
    <i> </i> $_SESSION['session_type'] = 'register';
    <i> </i> register();
    <i> </i> }
    <i> </i> }
    <i> </i> }
    <i> </i>}
    }


    function login()
    {
    if(!isset($_SESSION['session_type']) || $_SESSION['session_type'] != 'login')
    {
    //Close Statement.
    mysqli_stmt_close($stmt);
    //Close Connection.
    mysqli_close($conn);

    <i> </i> die("Could not check email! Please try again later!");
    <i> </i>}
    <i> </i>
    <i> </i>//$email = trim($_POST["email_account"]) . '@' . trim($_POST["email_service"]);
    <i> </i>$email = $_SESSION['email'];//If this fails on test then replace it with above line
    <i> </i>
    <i> </i>//Connect to Database. (DB_SERVER, BD_USERNAME, DB_PASSWORD, DB_NAME).
    <i> </i>$conn = mysqli_connect("localhost","root","","powerpage");
    <i> </i>
    <i> </i>//Prepare a Select Statement.
    <i> </i>$sql_query_3 = "SELECT id,username,first_name,middle_name,surname,gender,age_range FROM users WHERE personal_email = ?";
    <i> </i>if(!$stmt_3 = mysqli_prepare($conn,$sql_query_3))
    <i> </i>{
    <i> </i> //Close Statement.
    <i> </i> mysqli_stmt_close($stmt_3);
    <i> </i> //Close Connection.
    <i> </i> mysqli_close($conn);
    <i> </i>
    <i> </i> die("Could not check email! Please try again later!");
    <i> </i>}
    <i> </i>else
    <i> </i>{
    <i> </i> //Bind Variables to the Prepared Statement as parameters.
    <i> </i> mysqli_stmt_bind_param($stmt_3,'s',$email);
    <i> </i>
    <i> </i> //Attempt to execute the Prepared Statement.
    <i> </i> if(!mysqli_stmt_execute($stmt_3))
    <i> </i> {
    <i> </i> //Close Statement.
    <i> </i> mysqli_stmt_close($stmt_3);
    <i> </i> //Close Connection.
    <i> </i> mysqli_close($conn);
    <i> </i>
    <i> </i> die("Could not check email! Please try again later!");
    <i> </i> }
    <i> </i> //mysqli_stmt_bind_result($stmt,$email);
    <i> </i>
    <i> </i> $result_3 = mysqli_stmt_get_result($stmt_3);
    <i> </i>
    <i> </i> //if(mysqli_fetch_array($result_3, MYSQLI_NUM))
    <i> </i>
    <i> </i> //Fetch result row as an associative array. Since the result set contains only one row, we don't need to use the 'While loop'.
    <i> </i> //mysqli_stmt_fetch($stmt);//use this if you use 'mysqli_stmt_bind_result($stmt,$email).
    <i> </i> if($row = mysqli_fetch_array($result_3,MYSQLI_ASSOC)) //Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of 'mysqli_stmt_bind_result($stmt,$email)'.
    <i> </i> {
    <i> </i> //Retrieve Values.
    <i> </i> $id = $row["id"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    <i> </i> $username = $row["username"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    <i> </i> $first_name = $row["first_name"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    <i> </i> $middle_name = $row["middle_name"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    <i> </i> $surname = $row["surname"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    <i> </i> $gender = $row["gender"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    <i> </i> $age_range = $row["age_range"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    <i> </i>
    <i> </i> echo "Id: $id&lt;br&gt;";
    <i> </i> echo "Username: $username&lt;br&gt;";
    <i> </i> echo "First Name: $first_name&lt;br&gt;";
    <i> </i> echo "Middle Name: $middle_name&lt;br&gt;";
    <i> </i> echo "Surname: $surname&lt;br&gt;";
    <i> </i> echo "Gender: $gender&lt;br&gt;";
    <i> </i> echo "Age Range: $age_range&lt;br&gt;";
    <i> </i>
    <i> </i> //Close Statement.
    <i> </i> mysqli_stmt_close($stmt_3);
    <i> </i> //Free Result.
    <i> </i> mysqli_free_result($result_3);
    <i> </i> //Close Connection.
    <i> </i> mysqli_close($conn);
    <i> </i> }
    <i> </i>}
    }


    [upl-image-preview url=https://www.webdeveloper.com/assets/files/2020-06-02/1591104973-987435-1st-script-working.png]

    How come this one is echoing the rows with these still intact ?
    <i>
    </i>$result_3 = mysqli_stmt_get_result($stmt_3);
    mysqli_free_result($result_3);


    Check properly, there exist no:
  • * mysqli_stmt_init().

    And also exists:

  • * mysqli_stmt_free_result($stmt)

  • * Also note that, I used mysqli_prepare() and not mysqli_stmt_prepare().


  • And the above script is working fine. Look at the above img. Find it echoing the mysql tbl row.

    Infact, the code in my original post (that was failing to echo the rows) is a copycat skeleton of the just above mentioned code and so my original post's code (in this thread) should have worked to echo the row. But it doesn't.

    Anyway, I fixed this original post code like the following just now and it is working.

    Note: On this following one (original post code), it doesn't work unless I use mysqli_stmt_init($stmt).

    Plus, unlike the other one, I have to use mysqli_stmt_prepare() and simply using mysqli_prepare() throws error.

    Why is that ?

    So my questions to you now boils down to this:
  • 1. Why is mysqli_stmt_init() needed on the 2nd script but not on the 1st ?

    And,

  • 2. Why is mysqli_prepare() working on the 1st one but not on the 2nd one and mysqli_stmt_prepare() is needed instead ? (CONFUSING!)!


  • 2nd code (original post code that I just fixed):
    <i>
    </i>$sql_query = "SELECT username,first_name,middle_name,surname,gender,marital_status,working_status FROM users WHERE id = ?";
    $stmt = mysqli_stmt_init($conn);
    mysqli_stmt_prepare($stmt,$sql_query);
    mysqli_stmt_bind_param($stmt,'i',$_SESSION["user_id"]);//DELETE THIS WHOLE LINE AS USING IT AS A TEST!

    if($stmt == False)
    {
    //Close Connection.
    mysqli_close($conn);
    echo "Line 862&lt;br&gt;";//DELETE THIS
    die("&lt;pre&gt;2. Mysqli Prepare Failed!n".mysqli_stmt_error($stmt)."n$sql_query&lt;/pre&gt;");
    }

    //Attempt to Execute the Prepared Statement.
    mysqli_stmt_execute($stmt);
    if(!mysqli_stmt_execute($stmt))
    {
    //Close Connection.
    mysqli_close($conn);
    echo "Line 915&lt;br&gt;";//DELETE THIS
    die("&lt;pre&gt;Statement Execution Failed!n".mysqli_stmt_error($stmt)."nmysqli_stmt_bind_param&lt;/pre&gt;");
    }
    else
    {
    echo "&lt;pre&gt;Statement Execution Success!&lt;/pre&gt;";
    }
    //mysqli_stmt_bind_result($stmt,$email);

    $result = mysqli_stmt_get_result($stmt);

    //if(mysqli_fetch_array($result_3, MYSQLI_NUM))

    //Fetch result row as an associative array. Since the result set contains only one row, we don't need to use the 'While loop'.
    //mysqli_stmt_fetch($stmt);//use this if you use 'mysqli_stmt_bind_result($stmt,$email).

    if($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) //Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of 'mysqli_stmt_bind_result($stmt,$email)'.
    {
    //Retrieve Values.
    //$id = $row["id"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $username = $row["username"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $first_name = $row["first_name"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $middle_name = $row["middle_name"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $surname = $row["surname"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $gender = $row["gender"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    //$age_range = $row["age_range"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $marital_status = $row["marital_status"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    $working_status = $row["working_status"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';
    //$country = $row["country"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)';

    //echo "Id: $id&lt;br&gt;";
    //echo "Username: $username&lt;br&gt;";
    echo "First Name: $first_name&lt;br&gt;";
    echo "Middle Name: $middle_name&lt;br&gt;";
    echo "Surname: $surname&lt;br&gt;";
    echo "Gender: $gender&lt;br&gt;";
    //echo "Age Range: $age_range&lt;br&gt;";
    echo "Marital Status: $marital_status&lt;br&gt;";
    echo "Working Status: $working_status&lt;br&gt;";
    //echo "Country: $country&lt;br&gt;";

    //Close Statement.
    mysqli_stmt_close($stmt);
    //Free Result.
    //mysqli_free_result($result);//Is this line necessary if using mysqli_stmt_get_result() ?
    //Close Connection.
    mysqli_close($conn);
    }
    //mail();


    [upl-image-preview url=https://www.webdeveloper.com/assets/files/2020-06-02/1591105112-188627-2nd-script-working.png]

    Check properly, unlike 1st script, on this 2nd script, there DOES exist:
  • * mysqli_stmt_init().

    And also like the 1st script, on this 2nd script, exists:

  • * mysqli_stmt_free_result($stmt)

  • * Also note that, I used mysqli_stmt_prepare() here and not mysqli_prepare().


  • And the above script is working fine. Look at the above img. Find it echoing the mysql tbl row.

    What is your conclusion now ?

    Mine is: CONFUSING!

    @Sempervivum

    @ginerjm

    I'd appreciate it if Sempervivum and Ginerjm can chime in. Aswell as anybody else.

    Thanks!
    Copy linkTweet thisAlerts:
    @SempervivumJun 02.2020 — As far as I'm concerned:
  • 1. Far too much code, can't you extract the section that is relevant for your question or issue?

  • 2. When dealing with access to database I'm preferring PDO and do not like to dive into mysqli as it seems to me that PDO is most advanced and state of the art.
  • Copy linkTweet thisAlerts:
    @NogDogJun 02.2020 — For god's sake be consistent. Don't use mysqli_prepare() part of the time and mysqli_init() / mysqli_stmt_prepare() in others. Write code as if you're going to have to maintain it 2 years from now when you've forgotten what/why you did it in the first place -- because you most likely will have to.
    Copy linkTweet thisAlerts:
    @developer_webauthorJun 06.2020 — @NogDog#1619047

    Quite frankly, I wanted to use mysqli_stmt_prepare() but used mysqli_prepare() as typo.

    I see from php manual that you use mysqli_stmt_init() if you use mysqli_stmt_get_result(). That is all I know about mysqli_stmt_init(). Or is there more to it ?

    How come you never use mysqli_stmt_init() when using mysqli_stmt_bind_result() ?

    I am confused about this mydsqli_stmt_init() unless someone intends to shed some light here.
    Copy linkTweet thisAlerts:
    @NogDogJun 06.2020 — > @developer_web#1619191 I am confused about this mydsqli_stmt_init() unless someone intends to shed some light here.

    I've never used it, as I've been using PDO for all database interactions for at least 8 years now, so really don't know why you'd use either of those MySQLi patterns over the other one. For that matter, once I learned PDO, I don't know why you'd want to use MySQLi functions at all. ;)
    Copy linkTweet thisAlerts:
    @developer_webauthorJun 08.2020 — @NogDog#1619200

    @sempervivum

    I found the difference between mysqli_prepare() and mysqli_stmt_prepare().

    Either of following 2 is valid:

    1.
    <i>
    </i>$sql_query = "SELECT username,first_name,middle_name,surname,gender,marital_status,working_status FROM users WHERE username = ? ORDER by id LIMIT $row_start,$row_end";//Offset,Max Result.

    $stmt = mysqli_prepare($conn,$sql_query);


    2.
    <i>
    </i>$sql_query = "SELECT username,first_name,middle_name,surname,gender,marital_status,working_status FROM users WHERE username = ? ORDER by id LIMIT $row_start,$row_end";//Offset,Max Result.

    $stmt = mysqli_stmt_init($conn);

    mysqli_stmt_prepare($stmt,$sql_query);


    They say, the 2nd one is for procedural style. But I seen the 1st one works on my procedural style codes as I don't know oop.

    In other words, mysqli_prepare() is an alias. That is what I gathered so far.

    Gathered from here:

    https://stackoverflow.com/questions/31462215/what-is-the-difference-between-mysqli-prepare-and-mysqli-stmt-prepare

    Which pointed me to here:

    https://www.php.net/manual/en/mysqli-stmt.prepare.php

    You can do your own research:

    https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwiSjraXtfLpAhXhxTgGHfGIAcMQFjAAegQIARAB&url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F31462215%2Fwhat-is-the-difference-between-mysqli-prepare-and-mysqli-stmt-prepare&usg=AOvVaw1DP4v3csMHa9siRsLMJhb0
    ×

    Success!

    Help @developer_web spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...